Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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

Show:
© 2017 Microsoft