Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using IDisposable
Message
From
21/11/2008 16:47:31
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
21/11/2008 16:34:46
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Application:
Desktop
Miscellaneous
Thread ID:
01363570
Message ID:
01363575
Views:
14
>Can you put it in the destuctor?

I don't know Craig, I am having one of those days when I don't know what is right anymore. I just finished reading an article by a respected source that says and I quote
"The most important point to remember if you supply a destructor is that you cannot predict when it will be called - it will only be executed when the garbage collector runs and removes it from memory. It is for this reason that if you have any expensive unmanaged resources to release when your class is destroyed, it is preferable to dispose of them in a Close() or Dispose() method that can be called explicitly by the user of the class. In actual fact, we can never guarantee that a destructor will ever be called since we can tell the garbage collector NOT to call an object's destructor with the SuppressFinalize method of the System.GC class.
Does this insure my method would be called?


>
>>Hi All,
>>
>>Ok, I have added a method to my class that I want to be sure is run anytime this class goes away. Since you are not supposed to put a call to a method in Dispose then there isn't a valid reason for me to implement IDisposable. I am reluctant to put a public method for this and expect any using class to NOT forget to call it.
>>What is the right way to do this?
>>Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform