Example #1
0
 /// <summary>Ask the GC to collect and verify that it did something. Asserts that there were no Lua leaks.</summary>
 public static void GcAll()
 {
     ExecuteAndKill(() => {
         var o = new object();
         while (GC.GetGeneration(o) < GC.MaxGeneration)
         {
             GcCollect();
         }
         var gc = new GCTest(o);
         return(gc);
     });
                 #if DEBUG
     Assert.AreEqual(0u, Lua.PopLeakCount(), "Lua objects were leaked.");
                 #endif
 }
Example #2
0
        public void WeakReference_Test()
        {
            GCTest        obj  = new GCTest();
            WeakReference weak = new WeakReference(obj);

            obj = null;
            GC.Collect();
            bool alive = weak.IsAlive;

            Assert.IsFalse(alive);
            obj = weak.Target as GCTest;
            Assert.IsNull(obj);

            weak = new WeakReference(null);
            int n = 0;

            GC.Collect();
            weak = new WeakReference(n);
            n    = 1;
            GC.Collect();
        }