Esempio n. 1
0
    public static void Main()
    {
        TestReferenceCount1 t1, t2;

        t1 = new TestReferenceCount1();
        Assert(1, GC.ReferenceCount(t1));
        Assert(1, Count);

        // two vars pointing to the same object
        t2 = t1;
        Assert(2, GC.ReferenceCount(t1));
        Assert(2, GC.ReferenceCount(t2));
        Assert(1, Count);

        // point the second var to a new object
        t2 = new TestReferenceCount1();
        Assert(1, GC.ReferenceCount(t1));
        Assert(1, GC.ReferenceCount(t2));
        Assert(2, Count);

        // point the first var to the second object
        t1 = t2;
        Assert(1, Count);
        Assert(2, GC.ReferenceCount(t1));
        Assert(2, GC.ReferenceCount(t2));

        // set one of the vars to null
        t1 = null;
        Assert(1, Count);
        Assert(1, GC.ReferenceCount(t2));
    }
Esempio n. 2
0
    public static void Main()
    {
        TestReferenceCount1 t1, t2;
        t1 = new TestReferenceCount1();
        Assert( 1, GC.ReferenceCount(t1) );
        Assert( 1, Count );

        // two vars pointing to the same object
        t2 = t1;
        Assert( 2, GC.ReferenceCount(t1) );
        Assert( 2, GC.ReferenceCount(t2) );
        Assert( 1, Count );

        // point the second var to a new object
        t2 = new TestReferenceCount1();
        Assert( 1, GC.ReferenceCount(t1) );
        Assert( 1, GC.ReferenceCount(t2) );
        Assert( 2, Count );

        // point the first var to the second object
        t1 = t2;
        Assert( 1, Count );
        Assert( 2, GC.ReferenceCount(t1) );
        Assert( 2, GC.ReferenceCount(t2) );

        // set one of the vars to null
        t1 = null;
        Assert( 1, Count );
        Assert( 1, GC.ReferenceCount(t2) );

    }