Skip to content

Instantly share code, notes, and snippets.

@MisterKidX
Created October 26, 2022 14:25
Show Gist options
  • Save MisterKidX/ed739c39b8ddd86a5b41f15c87860ede to your computer and use it in GitHub Desktop.
Save MisterKidX/ed739c39b8ddd86a5b41f15c87860ede to your computer and use it in GitHub Desktop.
Showing how finalizers work
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