[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


VB6 Out of Memory Error

Posted on 2009-02-12
Medium Priority
Last Modified: 2013-12-25

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.

Question by:YellowbusTeam
  • 2
  • 2

Expert Comment

ID: 23644434
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.

Author Comment

ID: 23648636
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)


Accepted Solution

mlaise earned 1500 total points
ID: 23651643
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.


Author Comment

ID: 23659573
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.

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question