How to destroy (GC) a parent view and it's children?

Topics: Prism v4 - WPF 4
Mar 3, 2012 at 3:43 PM

I have a shell with a tab region that injects multiple tabs as workspaces.  Each workspace can be from a different module and usually has many injected/nested/child views.

When a view is removed from a region it is not destroyed/garbage collected.

Is there a supported method to removing and destroying a parent view which in turn cleans up all nested/child regions and views?

Or, do we have to come up with a manual approach by triggering some method when the view is removed, to then also destroy the view and any child components?

We're currently in WPF but may be switching to Silverlight if that has any bearing on things.

Thanks in advance.


Mar 5, 2012 at 12:51 PM


I believe you might find the optional ClearChildViewsRegionBehavior behavior that was added since Prism 4.1 useful to support scenarios where nested regions may need to be removed from the region manager when the parent view is removed from a region.

As mentioned in the Documentation Addendums for Prism 4.1 (inside Prism 4.1 readme.mht 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:

<UserControl x:Class="SomeModule.Views.RightView"
    xmlns:Regions=""  RegionBehaviors:ClearChildViewsRegionBehavior.ClearChildViews="True">

Also you could find more information in the following related work item:

I hope you find this useful,

Agustin Adami