Ejemplo n.º 1
0
    static void SetupLinks3()
    {
        var r = new Toggleref()
        {
            id = "root"
        };
        var c = new Toggleref()
        {
            id = "child"
        };

        r.__test = Toggleref.STRONG;
        c.__test = Toggleref.WEAK;
        Register(r);
        Register(c);
        root  = new WeakReference <Toggleref> (r, false);
        child = new WeakReference <Toggleref> (c, false);

        var root_val  = new object();
        var child_val = new object();

        cwt.Add(r, root_val);
        cwt.Add(c, child_val);

        root_value  = new WeakReference <object> (root_val, false);
        child_value = new WeakReference <object> (child_val, false);
    }
Ejemplo n.º 2
0
	static void SetupLinks () {
		var a = new Toggleref () { id = "root" };
		var b = new Toggleref () { id = "child" };
		a.link.Add (b);
		a.__test = Toggleref.STRONG;
		b.__test = Toggleref.WEAK;
		Register (a);
		Register (b);
		root = new WeakReference<Toggleref> (a, false);
		child = new WeakReference<Toggleref> (b, false);
	}
Ejemplo n.º 3
0
	static void SetupLinks () {
		var r = new Toggleref () { id = "root" };
		var c = new Toggleref () { id = "child" };
		r.link.Add (c);
		r.__test = Toggleref.STRONG;
		c.__test = Toggleref.WEAK;
		Register (r);
		Register (c);
		root = new WeakReference<Toggleref> (r, false);
		child = new WeakReference<Toggleref> (c, false);
	}
Ejemplo n.º 4
0
    static void SetupLinks2()
    {
        var r = new Toggleref()
        {
            id = "root"
        };
        var c = new Toggleref()
        {
            id = "child"
        };

        r.__test = Toggleref.STRONG;
        c.__test = Toggleref.WEAK;
        Register(r);
        Register(c);
        root  = new WeakReference <Toggleref> (r, false);
        child = new WeakReference <Toggleref> (c, false);
    }
Ejemplo n.º 5
0
    static int test_0_root_keeps_child()
    {
        Console.WriteLine("test_0_root_keeps_child");
        var t = new Thread(SetupLinks);

        t.Start();
        t.Join();

        GC.Collect();
        GC.WaitForPendingFinalizers();

        Console.WriteLine("try get A {0}", root.TryGetTarget(out a));
        Console.WriteLine("try get B {0}", child.TryGetTarget(out b));
        Console.WriteLine("a is null {0}", a == null);
        Console.WriteLine("b is null {0}", b == null);
        if (a == null || b == null)
        {
            return(1);
        }
        Console.WriteLine("a test {0}", a.__test);
        Console.WriteLine("b test {0}", b.__test);

        //now we break the link and switch b to strong
        a.link.Clear();
        b.__test = Toggleref.STRONG;
        a        = b = null;

        GC.Collect();
        GC.WaitForPendingFinalizers();

        Console.WriteLine("try get A {0}", root.TryGetTarget(out a));
        Console.WriteLine("try get B {0}", child.TryGetTarget(out b));
        Console.WriteLine("a is null {0}", a == null);
        Console.WriteLine("b is null {0}", b == null);
        if (a == null || b == null)
        {
            return(2);
        }
        Console.WriteLine("a test {0}", a.__test);
        Console.WriteLine("b test {0}", b.__test);


        return(0);
    }
Ejemplo n.º 6
0
    static void SetupLinks()
    {
        var a = new Toggleref()
        {
            id = "root"
        };
        var b = new Toggleref()
        {
            id = "child"
        };

        a.link.Add(b);
        a.__test = Toggleref.STRONG;
        b.__test = Toggleref.WEAK;
        Register(a);
        Register(b);
        root  = new WeakReference <Toggleref> (a, false);
        child = new WeakReference <Toggleref> (b, false);
    }
Ejemplo n.º 7
0
	static int Main ()
	{
		
		var t = new Thread (SetupLinks);
		t.Start ();
		t.Join ();
		
		GC.Collect ();
		GC.WaitForPendingFinalizers ();

		Console.WriteLine ("try get A {0}", root.TryGetTarget (out a));
		Console.WriteLine ("try get B {0}", child.TryGetTarget (out b));
		Console.WriteLine ("a is null {0}", a == null);
		Console.WriteLine ("b is null {0}", b == null);
		if (a == null || b == null)
			return 1;
		Console.WriteLine ("a test {0}", a.__test);
		Console.WriteLine ("b test {0}", b.__test);

		//now we break the link and switch b to strong
		a.link.Clear ();
		b.__test = Toggleref.STRONG;
		a = b = null;

		GC.Collect ();
		GC.WaitForPendingFinalizers ();

		Console.WriteLine ("try get A {0}", root.TryGetTarget (out a));
		Console.WriteLine ("try get B {0}", child.TryGetTarget (out b));
		Console.WriteLine ("a is null {0}", a == null);
		Console.WriteLine ("b is null {0}", b == null);
		if (a == null || b == null)
			return 2;
		Console.WriteLine ("a test {0}", a.__test);
		Console.WriteLine ("b test {0}", b.__test);


		return 0;

	}
Ejemplo n.º 8
0
	static int test_0_root_keeps_child ()
	{
		Console.WriteLine ("test_0_root_keeps_child");
		FinalizerHelpers.PerformNoPinAction (SetupLinks);
		
		GC.Collect ();
		GC.WaitForPendingFinalizers ();

		Console.WriteLine ("try get A {0}", root.TryGetTarget (out a));
		Console.WriteLine ("try get B {0}", child.TryGetTarget (out b));
		Console.WriteLine ("a is null {0}", a == null);
		Console.WriteLine ("b is null {0}", b == null);
		if (a == null || b == null)
			return 1;
		Console.WriteLine ("a test {0}", a.__test);
		Console.WriteLine ("b test {0}", b.__test);

		//now we break the link and switch b to strong
		a.link.Clear ();
		b.__test = Toggleref.STRONG;
		a = b = null;

		GC.Collect ();
		GC.WaitForPendingFinalizers ();

		Console.WriteLine ("try get A {0}", root.TryGetTarget (out a));
		Console.WriteLine ("try get B {0}", child.TryGetTarget (out b));
		Console.WriteLine ("a is null {0}", a == null);
		Console.WriteLine ("b is null {0}", b == null);
		if (a == null || b == null)
			return 2;
		Console.WriteLine ("a test {0}", a.__test);
		Console.WriteLine ("b test {0}", b.__test);


		return 0;
	}
Ejemplo n.º 9
0
	static void SetupLinks3 () {
		var r = new Toggleref () { id = "root" };
		var c = new Toggleref () { id = "child" };

		r.__test = Toggleref.STRONG;
		c.__test = Toggleref.WEAK;
		Register (r);
		Register (c);
		root = new WeakReference<Toggleref> (r, false);
		child = new WeakReference<Toggleref> (c, false);

		var root_val = new object ();
		var child_val = new object ();

		cwt.Add (r, root_val);
		cwt.Add (c, child_val);

		root_value = new WeakReference<object> (root_val, false);
		child_value = new WeakReference<object> (child_val, false);
	}