public void PromotedCwtPointingToYoungStuff()
        {
            var cwt = new ConditionalWeakTable <object, object> ();

            var handles = FillTable3(cwt);

            GC.Collect(0);

            /*Be 100% sure it will be on the young gen*/

            /*cwt array now will be on old gen*/
            ForceMinor();
            ForceMinor();
            ForceMinor();

            //Make them non pinned
            MakeObjMovable(handles);

            GC.Collect(0);

            //Force a minor GC - this should cause
            ForceMinor();
            ForceMinor();
            ForceMinor();
            ForceMinor();

            GC.Collect(0);

            object r1, r2;

            Assert.IsTrue(cwt.TryGetValue(handles[0].Target, out r1), "#1");
            Assert.IsTrue(cwt.TryGetValue(handles[1].Target, out r2), "#2");

            GC.Collect();
            cwt.GetHashCode();
        }
Ejemplo n.º 2
0
	public void PromotedCwtPointingToYoungStuff () {
		var cwt = new ConditionalWeakTable <object,object> ();

		var handles = FillTable3 (cwt);

		GC.Collect (0);

		/*Be 100% sure it will be on the young gen*/

		/*cwt array now will be on old gen*/
		ForceMinor ();
		ForceMinor ();
		ForceMinor ();

		//Make them non pinned
		MakeObjMovable (handles);

		GC.Collect (0);
		
		//Force a minor GC - this should cause
		ForceMinor ();
		ForceMinor ();
		ForceMinor ();
		ForceMinor ();

		GC.Collect (0);

		object r1, r2;
		Assert.IsTrue (cwt.TryGetValue (handles[0].Target, out r1), "#1");
		Assert.IsTrue (cwt.TryGetValue (handles[1].Target, out r2), "#2");

		GC.Collect ();
		cwt.GetHashCode ();
	}