Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
 }
Exemplo n.º 4
0
 public DirectDependent(SourceData source)
 {
     _source   = source;
     _property = new Dependent <int>(() => _source.SourceProperty);
 }
Exemplo n.º 5
0
 public void Initialize()
 {
     _source    = new SourceData();
     _dependent = new DirectDependent(_source);
 }
Exemplo n.º 6
0
 public DirectDependent(SourceData source)
 {
     _source = source;
     _property = new Dependent<int>(() => _source.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);
 }