Results 1 to 11 of 11

Thread: VB and Memory Leaks

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    VB and Memory Leaks

    If you are doing operations and VB needs more memory, it will allocate it. But unlike C, C++ or .Net VB will not release it until sometime after your app closes (There is no garbage collection). This would be the reason that some app run out of memory or run low on memory while in repetitive loops due to no fault of their own (well, sometimes it is their fault).

    Unfortunately there is nothing you can do to avoid this. All you can do it limit the damage by releasing the object you create (setting them to nothing). But, sooner or later if your app runs for any length of time... It will happen.

    The only way to avoid this is to restart your app when resources get low. Not great but that's the way it is....
    Last edited by randem; May 28th, 2005 at 06:10 AM.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB and Memory Leaks

    Does it still do it if the repetitive operations are in a class module and you set that to Nothing?

    I've never had any memory problems with VB that weren't caused by me.

  3. #3

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: VB and Memory Leaks

    penagate,

    Not all repetitive operations, just some. Sometimes they do not even have to be repetitive. But if you have a memory leak and do repetitive operations, you can get the "Out of Memory" error. VB inherently has memory leaks. Here is a sample project to show you how it happens.

    VB Memory Leak (11mb)

    This is an ADO example.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB and Memory Leaks

    Quote Originally Posted by randem
    This is an ADO example.
    If it's ADO then doesn't that mean it could be an issue with ADO? Or does it happen in other situations as well?

    Also, I can't get that link to work

  5. #5

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: VB and Memory Leaks

    penagate,

    Yes, Ado is the issue here but VB is still VB. If one component has it, then others have it. The link maybe slow right now but it does works.
    Last edited by randem; May 28th, 2005 at 06:11 AM.

  6. #6

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: VB and Memory Leaks

    penagate,

    Here is a DAO example where the same thing happens.

    VB Memory Leak 2 (25kb No database included, use database from other project)

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB and Memory Leaks

    I can't really see a huge issue with either of those...
    In the first one (looking at the log files) the memory usage actually went down, with the second one it very slowly went up (but not by much).

  8. #8

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: VB and Memory Leaks

    penagate,

    You have to look at the big picture, about 30mb of memory space goes missing with a full database and never returns until the file is unloaded. if I were to use that in a loop, it would not be long before I had a memory issue.

    Did you do the test with full database. There is a database VBMemLeak org.mdb that is full. Use the bat file to reset the database for each run.
    Last edited by randem; May 28th, 2005 at 06:46 AM.

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB and Memory Leaks

    Quote Originally Posted by randem
    penagate,

    You have to look at the big picture, about 30mb of memory space goes missing with a full database and never returns until the file is unloaded. if I were to use that in a loop, it would not be long before I had a memory issue.
    Yah, but wouldn't you load the database before the loop... and then once you are done with it, you unload it. If you keep a good track of what you are doing with your objects/files at all times, then you shouldn't run out of resources.

    I have memory issues with badly written classes... but that's solvable by re-writing the code. I'm not really convinced that there are any serious memory leaks with VB itself

  10. #10

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: VB and Memory Leaks

    penagate,

    No, you would not load the database then do the operation then close it. That is bad resource management. You would leave the database open for the whole time the app is open.

    The issue would happen in the loop. Each iteration would lose memory.

    I'm not really convinced that there are any serious memory leaks with VB itself
    If your app runs out of memory, you would not consider that serious? A couple of bytes or words of memory no, but this can be much more as I have shown.

    The Bold area is a serious memory leak just from running a simple SQL Statement.

    Code:
    5/28/2005 1:45:55 AM - ADOLeak vbMemLeak.txt Error Log - 
    
    Before .Execute - 164929536
    Delete from ProgramCheckOut where SYS_ID = 1
     After .Execute - 163868672
    
    Before .Execute - 163852288
    Delete from ProgramData where SYS_ID = 1
     After .Execute - 131428352
    
    Before .Execute - 131428352
    Delete from ProgramList where SYS_ID = 1
     After .Execute - 131293184
    
    Before .Execute - 131293184
    Delete from PathName where SYS_ID = 1
     After .Execute - 131248128
    
    Before .Execute - 131248128
    Delete from Title where SYS_ID = 1
     After .Execute - 131231744
    
    Before .Execute - 131231744
    Delete from LockOut where SYS_ID = 1
     After .Execute - 131215360
    Last edited by randem; May 28th, 2005 at 07:05 AM.

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB and Memory Leaks

    Oh. I see your point. I misinterpreted the numbers

    In that case yes there is some memory leak going on. I never really use databases so I haven't run into these sorts of problems before.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width