RegionManagerRegistrationBehavior never stop monitoring the RegionManager


When a view containing region(s) is removed, the reference to the view remain and the view never get disposed.
When view containing region(s) is removed from a region, RegionManagerRegistrationBehavior should stop monitoring the RegionManager to release the reference to the view.

Unfortunately, the RegionBehavior does not get notified when the region get detached.


vallekie wrote Mar 6, 2009 at 11:50 PM

Unfortunately, it's not possible to detect in Silverlight that a view (that contains regions) is removed from the Visual tree.

However, we are checking that, whenever you are accessing the regionmanager, if all the views are still part of the visual tree. If it turns out that a region no longer is part of the visual tree, we'll remove it from the regionmanager. Then the view should be removed.

It's not very straigtforward, but eventually the view should be released. However, if you find a situation where the views don't get released, then we'd like to know about it. Can you send a repro?


aadami wrote Sep 6, 2011 at 2:34 PM


You can check the following work item, where a similar concern is discussed and a workaround is proposed:
Remove view does not remove all sub-views (http://compositewpf.codeplex.com/workitem/5657)

I'm leaving this as an open suggestion so that the team reviews the way in which regions are removed from the region manager when the region is no longer part of the visual tree.


Agustin Adami

aadami wrote Mar 8, 2012 at 7:38 PM


For those interested in this subject, you might find useful to know that since Prism 4.1 release (http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=28950). To support scenarios where a view contains a nested region, and the nested regions may need to be removed from the region manager when the parent view is removed from a region, an optional behavior was added that will clear the RegionManager attached properties on those regions to force their removal from the region manager.

As mentioned in the Prism 4.1 readme file: While the behavior is registered and available for all regions, it is optionally enabled for a view containing nested regions by using the ClearChildViews attached property:

Agustin Adami