Skip to content

Instantly share code, notes, and snippets.

@chrisnas
Created January 12, 2019 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisnas/f1e29d9aa9565e2c33ce4d9d063797e0 to your computer and use it in GitHub Desktop.
Save chrisnas/f1e29d9aa9565e2c33ce4d9d063797e0 to your computer and use it in GitHub Desktop.
public class LargeObject : IDisposable
{
private static readonly Cleaner<LargeObject, NativeState> _cleaner;
static LargeObject()
{
_cleaner = new Cleaner<LargeObject, NativeState>(Cleanup, OnError);
}
private NativeState _state;
// Plus some heavy stuff that we don't want to keep around once the object is no more referenced
public LargeObject()
{
_state = new NativeState()
{
_handle1 = (IntPtr) (DateTime.Now.Ticks),
_handle2 = (IntPtr) (DateTime.Now.Ticks + 1),
};
_cleaner.Track(this, _state);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment