VB Garbage collection
This article claims it’s pointless to Set objects to Nothing in VB when you’re finished with them, except in particular cases. Maybe it’s those particular cases I’ve come up against, but I don’t believe that, myself. I’ve observed time and time again IIS apps that call VB6 DLLs grabbing more and more memory for DLLHost, and eventually choking until an iisreset has been done.
Going through the code (both the ASP VB Script and the underlying DLL VB) with a fine tooth comb and ensuring EVERY object got set to Nothing afterwards cleared these issues. Though I’m embarassed to admit that on one early project I worked on, a bunch of people looked through the code trying to find the leak, couldn’t find it, and someone eventually wrote a nightly iisreset batch job.
Reading that article, it occurs to me that maybe there was a case of destroying objects that referred to each other in the wrong order. The code is long sinced vanished, so I don’t know, and don’t care to find out.
As far as I’m concerned, it’s not only better for performance to destroy your objects, and a helluva lot easier to do all the time than just some of the time. It’s also tidier in the code. I’ll keep on doing it.
.Net, of course, is a different kettle of fish altogether.

December 12th, 2004 at 13:42
I’m with you - you create it, you destroy it.
December 18th, 2006 at 18:19
don’t know…garbage collection is an important issue, why not let the software handle the clerical job?
December 18th, 2006 at 21:40
Because, as I said in the article, it doesn’t handle it properly.
February 10th, 2007 at 07:03
If the VB runtime doesn’t handle garbage collection properly then setting your local variables to Nothing isn’t going to help any. What you are proposing is superstitious nonsense.
February 10th, 2007 at 11:49
Except I’ve seen it happen.
July 29th, 2007 at 09:59
I have a VB6 application which’s memory increases from 190 MB to 500 MB, time to time.
No memory leaking, as all objects are set to Nothing after usage.
So, VB6 DOES something weird with memory.
September 5th, 2007 at 23:55
Completely agree with daniel and Augusto, have recently been assigned to sifting through thousands of lines of code to try and find out why VB is refusing to release objects and my investigation has revealed that VB’s ‘Garbage Collector’ is no better than the London Underground during a tube strike