Disposing of a class

rmatthew

Centurion
Joined
Dec 30, 2002
Messages
115
Location
Texas
I have several classes that I need to implement a dispose method on. Problem being is when you dispose of the class it is still callable. Ie. I have esentially stopped everything that needs to be stopped but the hook still exist. I thow an exception if it has been disposed but how/when is the final disposition handled?
 
Have you read up on what Dispose is used for? If you're worried about being able to use an object once it's "disposed" then what you want is to set it to Nothing. Dispose is used when you need to free resources that must be freed immediately such as file handles, window handles, device contexts, etc.

Are you having problems with a program not shutting down after the last form is closed or something similar? To me a "hook" is something specific - it's when you are hooking into a window message handler or something "advanced".

Some clarification, please :)

-Nerseus
 
Sorry for the poor description and terminology.

I have a class object that use periodically. I want to shut it down (stop/abort a thread that is used, dump some data to a file, etc.) and free up the resources used by the class. Once 'disposed' I do not need/want to do anything with the class without having to declare a new one.

The document I referenced before indicates that the methods etc. are still available and that they should throw an exception (Which indicates to me that the class is not truly gone (free).

What I have done so far in the dispose function is take care of cleanup (as mentioned before). At the end I call GC.cleanup (to get rid of variables that are out of scope). But - like I said the document indicates that the class methods and class scoped variables are still active.

Would I be correct in assuming that if I call dispose, set the class declaration variable to nothing and call GC.cleanup that it would no longer be available and that all resources would be free?
 
think I found my answer :)

call some routine to do whatever cleanup I need and then set the thing to Nothing. This should set the pointer to 0 and on GC.cleanup it should reclaim - correct?
 
this article goes in to great depth on the garbage collector and how it cleans up resources, and when the responsibility lies with the programmer. I think you'll find it useful in this case :)
 
Back
Top