Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: l2k-Shadow on September 22, 2006, 08:47 PM

Title: [SOLVED] Correctly freeing an object
Post by: l2k-Shadow on September 22, 2006, 08:47 PM
Let's say I'm trying to access an ActiveX .dll using this code

Dim obj as Object
     Set obj = CreateObject("Project1.Class1")
     obj.HelloWorld

now how can I properly free this object?

Set obj = Nothing

is not doing it.

Unload obj

cannot be done
Title: Re: Correctly freeing an object
Post by: RealityRipple on September 22, 2006, 09:03 PM
IIRC, VB6 automatically unloads objects when the form they're on (or the sub/function they're in) are unloaded (or completed).
Title: Re: Correctly freeing an object
Post by: l2k-Shadow on September 22, 2006, 09:15 PM
Well I have the object loaded in a public variable to do things with it throughout the program until I need to unload it, and I just want to unload that object, not the entire program.
Title: Re: Correctly freeing an object
Post by: RealityRipple on September 22, 2006, 09:51 PM
Ah... I'm not sure you can do that... Try creating a form that acts as the holder of the object, and then Loading/Unloading the form when you want to load/unload the object. Remember to Set Form1 = Nothing when you unload.
Title: Re: Correctly freeing an object
Post by: l2k-Shadow on September 22, 2006, 10:25 PM
Quote from: RealityRipple on September 22, 2006, 09:51 PM
Ah... I'm not sure you can do that... Try creating a form that acts as the holder of the object, and then Loading/Unloading the form when you want to load/unload the object. Remember to Set Form1 = Nothing when you unload.

i'd rather not unload it than do something so lame.
Title: Re: Correctly freeing an object
Post by: Cat Food on September 22, 2006, 11:32 PM
I have a great quote of some newb saying someone was an idiot because of a memory leak in their application, and that they didn't know how to unload objects when finishing the use of them. When infact there was no memory leak involved in the program.

Oh wait...that newb was.... ---THIS ARROW POINTS UP---^
Title: Re: Correctly freeing an object
Post by: Stealth on September 23, 2006, 02:12 AM
Set obj = Nothing has worked for me in the past.. where have you seen a problem with it?
Title: Re: Correctly freeing an object
Post by: l2k-Shadow on September 23, 2006, 10:54 AM
I solved this thanks.