public void IndirectDependentObjectCanBeGarbageCollected() { GC.Collect(); SourceData independent = new SourceData(); DirectDependent intermediate = new DirectDependent(independent); IndirectDependent indirectDependent = new IndirectDependent(intermediate); independent.SourceProperty = 42; Assert.AreEqual(42, indirectDependent.DependentProperty); WeakReference weakIndirectDependent = new WeakReference(indirectDependent); GC.Collect(); Assert.IsTrue(weakIndirectDependent.IsAlive, "Since we hold a strong reference to the dependent, the object should still be alive."); // This assertion here to make sure the dependent is not optimized away. Assert.AreEqual(42, indirectDependent.DependentProperty); indirectDependent = null; GC.Collect(); Assert.IsFalse(weakIndirectDependent.IsAlive, "Since we released the strong reference to the dependent, the object should not be alive."); // Make sure we can still modify the independent, and that the intermediate still depends upon it. independent.SourceProperty = 32; Assert.AreEqual(32, independent.SourceProperty); Assert.AreEqual(32, intermediate.DependentProperty); }
public void DirectDependentObjectCanBeGarbageCollected() { GC.Collect(); SourceData independent = new SourceData(); DirectDependent dependent = new DirectDependent(independent); independent.SourceProperty = 42; Assert.AreEqual(42, dependent.DependentProperty); WeakReference weakDependent = new WeakReference(dependent); GC.Collect(); Assert.IsTrue(weakDependent.IsAlive, "Since we hold a strong reference to the dependent, the object should still be alive."); // This assertion here to make sure the dependent is not optimized away. Assert.AreEqual(42, dependent.DependentProperty); dependent = null; GC.Collect(); Assert.IsFalse(weakDependent.IsAlive, "Since we released the strong reference to the dependent, the object should not be alive."); // Make sure we can still modify the independent. independent.SourceProperty = 32; Assert.AreEqual(32, independent.SourceProperty); }
public void Initialize() { _source = new SourceData(); _intermediateDependent = new DirectDependent(_source); _dependent = new IndirectDependent(_intermediateDependent); }
public void Initialize() { _source = new SourceData(); _dependent = new DirectDependent(_source); }
public void Initialize() { _source = new SourceData(); _intermediateDependent = new DirectDependent(_source); _dependent = new IndirectDependent(_intermediateDependent); }
public void Initialize() { _source = new SourceData(); _dependent = new DirectDependent(_source); }
public IndirectDependent(DirectDependent indermediateDependent) { _indermediateDependent = indermediateDependent; _property = new Dependent<int>(() => _indermediateDependent.DependentProperty); }
public IndirectDependent(DirectDependent indermediateDependent) { _indermediateDependent = indermediateDependent; _property = new Dependent <int>(() => _indermediateDependent.DependentProperty); }