Skip to content

Instantly share code, notes, and snippets.

@0x414c49
Created December 23, 2019 15:46
Show Gist options
  • Save 0x414c49/ec373dcb7910221d0638e9d38d18518c to your computer and use it in GitHub Desktop.
Save 0x414c49/ec373dcb7910221d0638e9d38d18518c to your computer and use it in GitHub Desktop.
WeakReference.cs
class Program
{
static WeakReference _weakStringBuilder =
new WeakReference(new StringBuilder());
static void Main(string[] args)
{
if (_weakStringBuilder.IsAlive)
Console.WriteLine("Alive");
GC.Collect();
if (!_weakStringBuilder.IsAlive)
Console.WriteLine("Sade, it is colleced.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment