Skip to content

Instantly share code, notes, and snippets.

@chrisnas
Last active January 16, 2019 14:16
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/34b055f6eac364f067a9934c186e6bbd to your computer and use it in GitHub Desktop.
Save chrisnas/34b055f6eac364f067a9934c186e6bbd to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
InnerScope();
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine("Done");
Console.ReadLine();
// use the following code to explicitly stop the cleaner thread
//LargeObject.DisposeCleaner();
// the code is working without this call because the ticking thread
// is a background thread and won't stop the CLR to exit the process
}
static void InnerScope()
{
var largeObject = new LargeObject();
// it is also possible to support explicit disposing
// var largeObject2 = new LargeObject();
// largeObject2.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.KeepAlive(largeObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment