VB6 Out of Memory Error

Posted on 2009-02-12
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
    LVL 5

    Expert Comment

    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

    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)

    LVL 5

    Accepted Solution

    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

    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

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    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…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now