Created
October 26, 2022 14:25
-
-
Save MisterKidX/ed739c39b8ddd86a5b41f15c87860ede to your computer and use it in GitHub Desktop.
Showing how finalizers work
This file contains hidden or 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
Managed managed = new Managed(); | |
await Task.Delay(1000); | |
Console.WriteLine("managed is now null."); | |
managed = null; | |
Console.WriteLine("press any key to make the GC collect"); | |
Console.ReadLine(); | |
GC.Collect(); | |
Console.ReadLine(); | |
class Managed | |
{ | |
int X; | |
~Managed() | |
{ | |
Console.WriteLine("Managed object has been cleaned up."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment