Linker IT Software
Google
Web www.oraxcel.com
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
VB6 slow in disposing a lot of objects (Read 2239 times)
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
VB6 slow in disposing a lot of objects
12.10.09 at 16:38:28
 
VB6 slow in disposing a lot of objects
 
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'.
Back to top
 
« Last Edit: 12.10.09 at 16:39:40 by Gerrit-Jan Linker »  

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1