How do I dispose my own class objects?

suchiate

Member
Joined
Jan 4, 2006
Messages
11
Programming Experience
1-3
Hey all,

I have written some classes and uses various objects
to access the methods in my class..

can anyone tell me how to dispose my objects or
write a dispose function?

Thanks alot.
 
Eventually, yes, but if you read about the inner workings of the garbage collector, you will see that it may take some 'generations' before the object is fully disposed, as for explicit disposing it should be done first generation.
 
Just as a footnote, i really woudn't worry too much about reading up the generations of the garbage collector. There is only 3 and suffice to say that generation 1 is the shortest lived, and 3 is the longest lived. Shared variables are automatically promoted to the third generation, local variables as long as they are set to nothing as soon as they are finshed with shoudn't get past the first generation. However this is somewhat of a contentious point as the garbage collector can be a bit unpredictable. Also i would advise you to stay away from calling the garbage collector to collect explicitly as this, in most cases will actually slow down your app. Finally the actual release of managed resources, well the buck stops with the CLR it won't release memory until it 'decides' to.
Leave the garbage collecting to the GC and as johnH has said, just make sure that you have disposed of your object as soon as they are done with. Also look into GC.SuppressFinalize for use with IDisposable.
 
Back
Top