Esempio n. 1
0
        public void TestGetWeakReferenceDelegateAllowsObjectToBeGarabageCollected()
        {
            TargetClass targetClass = new TargetClass();
            WeakReference weakRefTargetClass = new WeakReference(targetClass);

            SomeDelegate d = targetClass.GetWeakReferenceDelegate();
            string actualTextResultFromCall = d();
            targetClass = null;
            GCHelper.ForceAndWaitGarbageCollection();

            Assert.False(weakRefTargetClass.IsAlive);
            //we also make sure the call to the method is done
            Assert.Equal(ExpectedText, actualTextResultFromCall);
        }