Game Development Reference
In-Depth Information
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
// Prevent issues with multi-threading
lock (this)
{
if (disposing)
{
// Perform cleanup on managed objects
}
// Perform cleanup on unmanaged objects
}
}
~YourClass()
{
Dispose(false);
}
}
Note
The disposing boolean parameter passed into the Dispose method will be true if explicitly called
by the user, and false if called by the garbage collector during finalization.
The following code shows the proper way to implement IDisposable with support
for finalization in a derived class. It is important to note that this code does not
have a Finalize method or a non-parameterized Dispose method because these
methods are inherited from the base class.
public class YourDerivedClass : YourClass
{
protected override void Dispose(bool disposing)
{
// Prevent issues with multi-threading
lock (this)
{
 
Search Nedrilad ::




Custom Search