Skip to content

Instantly share code, notes, and snippets.

@philcockfield
Created July 19, 2012 20:08
Show Gist options
  • Save philcockfield/3146438 to your computer and use it in GitHub Desktop.
Save philcockfield/3146438 to your computer and use it in GitHub Desktop.
Full implementation of IDisposable
using System;
using MonoTouch.Foundation;
namespace Core
{
public class Foo : NSObject, IDisposable
{
public Foo()
{
}
~Foo()
{
Dispose(false);
}
public bool IsDisposed { get; private set; }
public void Dispose()
{
base.Dispose(true);
GC.SuppressFinalize(this);
}
protected new virtual void Dispose(bool isDisposing)
{
// Setup initial conditions.
if (IsDisposed) return;
// Perform disposal or managed resources.
if (isDisposing)
{
// Dispose of managed resources.
}
// Finish up.
IsDisposed = true;
}
}
}
@philcockfield
Copy link
Author

// Light weight Disposable implementation.
public class Bar : NSObject, IDisposable
{
public void Dispose()
{
base.Dispose(true);
GC.SuppressFinalize(this);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment