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 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.

Implementing a Dispose Method

Describes the implementation of the Dispose method for releasing unmanaged resources.

Finalize Methods and Destructors

Describes how Finalize methods and destructors allow an object to perform necessary cleanup operations before the garbage collector automatically reclaims the object's memory.

Overriding the Finalize Method

Describes the way the Finalize and Dispose methods work together.

Destructor Syntax in C# and C++

Describes the C# and C++ equivalents of the Finalize method.

Using Objects That Encapsulate Resources

Describes ways to ensure that the Dispose method is called, such as the C# using statement (Using in Visual Basic).

System.IDisposable

Defines the Dispose method for releasing unmanaged resources.

Community Additions

Show:
© 2016 Microsoft