I know that i should use WeakReference just for large objects, but I am curious about the following scenario:
object obj = 1; //Int32
var wk = new WeakReference(obj);
Console.WriteLine(wk.IsAlive); //Prints: True
obj = null;
GC.Collect(2, GCCollectionMode.Forced, true);
Console.WriteLine(wk.IsAlive); //Prints: false, All Rigth!
So far it's alright.
Look this:
object obj = "test"; //String
var wk = new WeakReference(obj);
Console.WriteLine(wk.IsAlive); //Prints: True
obj = null;
GC.Collect(2, GCCollectionMode.Forced, true);
Console.WriteLine(wk.IsAlive); //Prints: True, Why?
what's going on?