VB6 "Out of Memory" error (7) dimensioning public array with plenty of physical memory free
Posted on 2005-04-08
My application throws a "error 7 - out of memory" when i dimension an array of 9million records of 48byte user-defined type (i.e. approximately 500Mb). There is plenty (about 3 Gig) of physical memory available on the machine and yet it immediately errors when dimming the array. It does not fail, however, on approximately 7 million records.
Machine spec is dual processor (~ 1.7 GHz each) server with 4 Gb physical memory and 2-4 Gb virtual memory.
I have entered the offending code into a new application (see below) which simply dimensions the same public array. This application will happily dimension the same array with as many as 20 million rows (about 1.5 gig). If i run it on the same machine at the point where the main app fails it works! i.e. the operating system will allocate THIS app the memory but not the other.
The main application has many public variables, some of them collections with up to a few thousand members. The test app has 1 public variable. I'm thinking perhaps there is a limit to the number/size of public variables within VB6?
Any help would be most appreciated! (thanks in advance)
Here is the code in the test app (that works):
Const CLILEN = 30
stUser As String * CLILEN ' all fixed size
lDate As Long ' value YYMMDD
lTime As Long ' value HHnnSS
iFlag As Integer ' for counting 'revenue'
' pointing to
ixFile As Integer ' a dated events (DEF)
lxRecord As Long ' in file
sEventType As String * 2 ' event type, e.g. "WG"
Public aSortIndex() As bulk_index_row
Private Sub cmdTest_Click()
Dim lCalls As Long
Dim bulkindexrec As bulk_index_row
On Error GoTo procErr
lCalls = 9000000
ReDim aSortIndex(0 To lCalls)