public void StrongBindingDoesNotRetainNotifier() { var binding = new BindingClass(); var notifying = new NotifyingClass(); // Means of determining whether the class has been disposed var weakNotifying = new WeakReference <NotifyingClass>(notifying); // Retain the IPropertyChangedBinding, in case that causes NotifyingClass to be retained var binder = binding.BindStrong(notifying); notifying = null; GC.Collect(); Assert.IsFalse(weakNotifying.TryGetTarget(out notifying)); }
public void StrongBindingDoesNotRetainNotifier() { WeakReference Test(out IEventBinding binder) { var binding = new BindingClass(); var notifying = new NotifyingClass(); // Retain the IPropertyChangedBinding, in case that causes NotifyingClass to be retained binder = binding.BindStrong(notifying); return(new WeakReference(notifying)); } var weakNotifying = Test(out var retained); GC.Collect(); Assert.IsFalse(weakNotifying.IsAlive); GC.KeepAlive(retained); }
public void StrongBindingDoesNotRetainNotifier() { var binding = new BindingClass(); var notifying = new NotifyingClass(); // Means of determining whether the class has been disposed var weakNotifying = new WeakReference<NotifyingClass>(notifying); // Retain the IPropertyChangedBinding, in case that causes NotifyingClass to be retained var binder = binding.BindStrong(notifying); notifying = null; GC.Collect(); Assert.IsFalse(weakNotifying.TryGetTarget(out notifying)); }