Fighting Memory Leaks
Posted on 2002-03-06
Each time I run our VB app, I can see available physical memory dropping. My problem is that I don't have any experience with combatting VB memory leaks. I could sure use some words of wisdom on general technique.
I presume I have caused the problem by allocating memory for objects (like forms) which I don't release.
For example, I keep several copies of some forms loaded but not shown, so that response is very quick. It works just fine, but I suspect is the cause of at least some of my memory problems.
I have an array of forms, like so:
Private FormsArray(100) As Form
When I need to create a form, I do this:
Set FormsArray(Index) = New frmXXX
When I'm done with the form, all I do is Unload it. That's probably where I'm going wrong. I probably ought to do this:
Set FormsArray(Index) = Nothing
In general, when looking for a memory leak, I should find all "New's" and make sure I eventually set those variables to "Nothing".
That's a question, not an assertion. What else should I look for?