• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • Last Modified:

VB6 Out of Memory Error


We have a fairly large VB application (approx 150 objects; 90,000 lines of code) and in the last 4 months or so we have started to get random out of memory errors (error code 7). We have a large number of error trapping in place and it does seem to happen in similar areas of the code, however these sections of code are fairly simple and if you run through them manually they work fine.

Then randomly all of a sudden a user will receive an out of memory error. It also seems to only happen on 3 or 4 different user's machines. We have checked all machines are up to date with the latest service packs etc and also we have checked their memory performance for example:

User: XXX
Machine Name: XXX
Last Procedure:frmClientSingleEmail:SendEmail
Last Line No:760
Memory Info:
Total physical memory :2,086,988K (Available :1,329,820K) Total Page file :-715,632K (Available :-1,339,404K) Total Virtual memory :2,097,024K (Available :1,888,596K Extended :0K) Memory Load :36%

Current Usage :60,328K

Open Forms:

The memory status is returned by API function calls and we assume them to be correct. We have searched google for hours on end trying to find a solution, we have also spent 50 hours tidying up the code so that all objects are disposed of etc when we have finished using them.

We just cannot get to the bottom of this. Any help is appreciated.

  • 2
  • 2
1 Solution
The only time I have seen that happen is when the code allows of the execution of infinite loops.  I would ask the users that get the issue to show you the EXACT thing they did right before the event happened, down to what they had all the controls set to.  Ask of the application seemed to 'hang' right before the out of mem error appeared.

Before seaching the code top to bottom for objects that are not being removed from memory I would take a long look at the data being passes into the code.  99% of the time I have found that most programmers do not safe code for the unexpected data.
YellowbusTeamAuthor Commented:
As the above example showed, we see a number of the out of memory errors appear when the code hits a line .sendtoqueue which is an ASP email command, which basically gets the email and sends it to the email queue and sends the email. Although this is part of a loop (when sending mass emails) there are no instances where it would be infinite.

Also as a random example we received the message on line 40 in the following code extract:

30      If Not booSearching Then
40        If glngClientID = 1000 Then
50          glngClientID = 0
60          If Not rsClients.EOF Then glngClientID = rsClients("ClientID")
70          GoTo Finish
80        End If
90      End If

As you can see it's pretty simple what this is doing and yet it throws a silly out of memory error!? This extract is not part of any loop. (glngClientID is a Long variable)

Here is a little info on some of the more obscure reasons you can get memory issues with Visual Basic 6.


If you are loading extremely large recordsets you also might want to look into the GetRows method on the recordset object.  It returns the results into a array so you do not have to maintain the ADO object in memory with all of the overhead.

YellowbusTeamAuthor Commented:
Hi mlaise,

Thanks for your help, those articles are the ones we have been coming across whilst searching google for a long time! We're just about to implement a version of the software which a much reduced public variable count, we found some were not used, some were only used locally and the rest we made into properties.

We have tried implementing the rest of the ideas, such as breaking up modules into smaller ones etc.

It seems the change we are just about to implement is the same as http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21991376.html

So hopefully it will work, I will update the post once we have found out, should be approx a week, as we need to implement and then wait for another out of memory error to occur.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now