Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

Cleaning Up Unmanaged Resources

You should prevent users of your application from calling an object's Finalize method directly by limiting its scope to protected. In addition, you are strongly discouraged from calling a Finalize method for a class other than your base class directly from your application's code. To properly dispose of unmanaged resources, it is recommended that you implement a public Dispose or Close method that executes the necessary cleanup code for the object. The IDisposable interface provides the Dispose method for resource classes that implement the interface. Because it is public, users of your application can call the Dispose method directly to free memory used by unmanaged resources. When you properly implement a Dispose method, the Finalize method (or destructor, in C# or the Managed Extensions for C++) becomes a safeguard to clean up resources in the event that the Dispose method is not called. For more information on correct implementation, see Implementing a Dispose Method.

See Also

IDisposable Interface | Implementing a Dispose Method | Overriding the Finalize Method | Using C# and Managed Extensions for C++ Destructor Syntax

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.