示例#1
0
    static void Main(string[] args)
    {
        ClassA          a     = new ClassA();
        ReferenceClassB b     = (ReferenceClassB)a.GetType().GetField("reference", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(a);
        WeakReference   weakA = new WeakReference(a);
        WeakReference   weakB = new WeakReference(b);

        a = null;
        b = null;
        GC.Collect();
        Debug.Assert(weakA.IsAlive == false);
        Debug.Assert(weakB.IsAlive == false);
    }
示例#2
0
 public ClassA()
 {
     reference = new ReferenceClassB(this);
 }