Skip to content

Instantly share code, notes, and snippets.

@Porges
Created May 2, 2012 23:39
Show Gist options
  • Save Porges/2581936 to your computer and use it in GitHub Desktop.
Save Porges/2581936 to your computer and use it in GitHub Desktop.
'using' holds a reference to the object being disposed
using System;
static class Program
{
public static void Main()
{
using (new Slow()) ;
}
}
class Slow : IDisposable
{
~Slow()
{
Console.WriteLine("collected");
}
public void Dispose()
{
Console.WriteLine("start method");
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine("end method");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment