Last active
January 16, 2019 14:16
-
-
Save chrisnas/34b055f6eac364f067a9934c186e6bbd to your computer and use it in GitHub Desktop.
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
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