Поделиться через


IDisposable Interface

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Defines a method to release allocated resources.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Interface IDisposable
[ComVisibleAttribute(true)]
public interface IDisposable

The IDisposable type exposes the following members.

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Dispose Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Top

Remarks

The primary use of this interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used. However, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams.

Most Silverlight-based applications consume unmanaged resources only when you access isolated storage with the IsolatedStorageFile class. A good practice is to use the using statement (Using in Visual Basic) with classes that use unmanaged resources, because the using statement calls Dispose for you after your code is finished with the object. For an example of the using statement being used with the IsolatedStorageFile class, see Isolated Storage.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference