Visual Basic 6 (VB6) is slow in disposing objects. This becomes more and more a problem with an increasing number of objects. Each object allocates some memory, whatever the object does, and deallocating this memory is where the problem is. Usually this is left to the VB garbage collector to do. This process can be terribly slow when having an enormous number of objects in memory. The problem occurs e.g. when having 100,000 objects in memory.

To see this problem in action, create a VB project with a class file (call it just class1). Run the following code:

Dim lng As long Dim col as new collection Dim c as Class1

For lng = 1 to 1000000 Set c = new Class1 col.add c Next lng

'Now we have a million objects of class1. Can be just an empty class.

'Setting the collection to nothing will cause the garbage collector to cleanup all the objects. 'The above creation will probably take a minute. The next statement will take 10 minutes if not longer

Set col = Nothing.

Solution: Use a public type instead of a class. Add a variable of that public type to a collection. Setting the collection to nothing will be quick. Takes a few seconds, even for a million 'objects'.

Copyright (C) 1995-2007 Linker IT
Software BV. All Rights Reserved. Oracle is a registered trademark of
Oracle corporation. Excel and Office are registered trademarks of
Microsoft corporation. Other names appearing on the site may be trademarks
of their respective owners. Software,
files, documents, articles and other material are provided
"as is" and without warranties as to performance or mechantability or
any other warranties whether expressed or implied. No
warranty of fitness for a particular purpose is offered.
sitemap