Note: You must be registered in order to post a reply.
T O P I C R E V I E W
Threshold
Posted - Apr 14 2005 : 2:11:16 PM If any of you have worked with Java, you'll have heard about Java's garbage collector which consistently deletes object instances of objects which are no longer referenced.
I was wondering, does VB do this or do you always have to set your objects to Nothing when finished with them?
4 L A T E S T R E P L I E S (Newest First)
Threshold
Posted - Apr 16 2005 : 7:28:51 PM I'm glad to hear it. Thanks for the info.
Eric Coleman
Posted - Apr 15 2005 : 4:22:42 PM Try the following instead of "End"
Dim f As Form For Each f In Forms Unload f Next
And if you're using a Sub Main, use "Exit Sub" right after that bit of code.
VBBR
Posted - Apr 15 2005 : 11:17:20 AM How could I end the app wothout using "End"? Only by unloading all forms and/or going thru all of the Main() sub?
Eric Coleman
Posted - Apr 14 2005 : 6:31:09 PM VB6 uses reference counting, as all COM Classes do. In C++ you have to do the reference counting manually. In VB it's done automatically for you in most cases. You can still be susceptible to circular references which you should try to avoid. When an object is no longer referenced VB6 will free it's memory immediately. VB6 will automatically dereference objects for you when they go out of scope, so you could create an object within a sub and when the sub is finished VB will automatically clean up for you. The same goes with arrays. VB releases memory based on the scope. When a variable is out of scope its memory is released.
VB6 is really good with preventing memory leaks. Of course, they can still happen, such as using LSET the wrong way or the circular reference problem mentioned above. Another source of memory leaks is using the "End" statement to end a vb program. Other leaks can happen with 3rd party controls and the windows API. Overall, pure VB6 code handles memory really well.