//ref http://caliburn.codeplex.com/WorkItem/View.aspx?WorkItemId=6100 //see also http://caliburn.codeplex.com/Thread/View.aspx?ThreadId=212171 public void backreferences_should_not_leak_the_observer() { var handlerRef = new WeakReference(handler); //this reference emulates a back pointer to a long-living model var parent = notifier.Model; ConfigureObserver(new[] { "Model.SomeModelProperty" }); //emulates the collection of the cluster composed by Screen, View, MessageHandler and ancillary filters //(included Dependecies along with its internal PropertyPathMonitor) observer = null; handler = null; GC.Collect(); GC.WaitForFullGCComplete(); GC.WaitForPendingFinalizers(); handlerRef.IsAlive.ShouldBeFalse(); //the first time a ppMonitor is notified AFTER the collection of its DependenyObserver, //it unregisters the unnecessary handler parent.NotifyOfPropertyChange("anyProperty"); parent.SubscriptionCount.ShouldBe(0); }
protected override void given_the_context_of() { _expectationsWasSet = false; var methodFactory = new DefaultMethodFactory(); _handler = StrictMock<IRoutedMessageHandler>(); _notifier = new TheNotifierClass(); _observer = new DependencyObserver(_handler, methodFactory, _notifier); _trigger = Mock<IMessageTrigger>(); }
protected override void given_the_context_of() { expectationsWasSet = false; var methodFactory = new DefaultMethodFactory(); handler = StrictMock <IRoutedMessageHandler>(); notifier = new TheNotifierClass(); observer = new DependencyObserver(handler, methodFactory, notifier); trigger = Mock <IMessageTrigger>(); }
//see http://caliburn.codeplex.com/Thread/View.aspx?ThreadId=212171 for the rationale behind the finalizer removal public void backreferences_should_not_leak_the_observer_strict() { var handlerRef = new WeakReference(handler); var parent = notifier.Model; ConfigureObserver(new[] { "Model.SomeModelProperty" }); observer = null; handler = null; GC.Collect(); GC.WaitForFullGCComplete(); GC.WaitForPendingFinalizers(); handlerRef.IsAlive.ShouldBeFalse(); parent.SubscriptionCount.ShouldBe(0); }
//see http://caliburn.codeplex.com/Thread/View.aspx?ThreadId=212171 for the rationale behind the finalizer removal public void backreferences_should_not_leak_the_observer_strict() { var handlerRef = new WeakReference(_handler); var parent = _notifier.Model; ConfigureObserver(new[] { "Model.SomeModelProperty" }); _observer = null; _handler = null; GC.Collect(); GC.WaitForFullGCComplete(); GC.WaitForPendingFinalizers(); Assert.That(handlerRef.IsAlive, Is.False); Assert.That(parent.SubscriptionCount, Is.EqualTo(0)); }
//ref http://caliburn.codeplex.com/WorkItem/View.aspx?WorkItemId=6100 //see also http://caliburn.codeplex.com/Thread/View.aspx?ThreadId=212171 public void backreferences_should_not_leak_the_observer() { var handlerRef = new WeakReference(_handler); //this reference emulates a back pointer to a long-living model var parent = _notifier.Model; ConfigureObserver(new[] { "Model.SomeModelProperty" }); //emulates the collection of the cluster composed by Screen, View, MessageHandler and ancillary filters //(included Dependecies along with its internal PropertyPathMonitor) _observer = null; _handler = null; GC.Collect(); GC.WaitForFullGCComplete(); GC.WaitForPendingFinalizers(); Assert.That(handlerRef.IsAlive, Is.False, "message handler has not been released"); //the first time a ppMonitor is notified AFTER the collection of its DependenyObserver, //it unregisters the unnecessary handler parent.NotifyOfPropertyChange("anyProperty"); Assert.That(parent.SubscriptionCount, Is.EqualTo(0), "subscription to parent model has not been removed"); }