Created
May 2, 2012 23:39
-
-
Save Porges/2581936 to your computer and use it in GitHub Desktop.
'using' holds a reference to the object being disposed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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