rmatthew Posted January 26, 2003 Posted January 26, 2003 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? Quote
*Experts* Nerseus Posted January 26, 2003 *Experts* Posted January 26, 2003 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
rmatthew Posted January 26, 2003 Author Posted January 26, 2003 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? Quote
rmatthew Posted January 26, 2003 Author Posted January 26, 2003 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? Quote
*Gurus* divil Posted January 26, 2003 *Gurus* Posted January 26, 2003 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 :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.