open System
let WeakReferenceExample() =
let mutable obj = new Object();
let weak = new WeakReference(obj);
GC.Collect();
Console.WriteLine("IsAlive: {0}\nobj <> null is {1}\n---", weak.IsAlive, obj <> null);
obj <- null;
GC.Collect();
Console.WriteLine("IsAlive: {0}", weak.IsAlive);
WeakReferenceExample()
Console.ReadKey()
Translated from the Rx In Action book sample. The above when run gives the following output which is different than what I get when I compile it in C# and run it.
IsAlive: True
obj <> null is True
---
IsAlive: True
Why is the weak reference not getting collected?