I am using Prism with MEF bootstrapper and MVVM design pattern.
I have a TabControl and I am creating a new scoped region manager for every tabItem which holds the same usercontrol (which has nested regions in it): regionManager.Regions["TAB_REGION"].Add(theView, null, true);
[I am not assigning any variable to the new scoped regionmanager. Also, theView is NonShared and is created for each tabItem and contains some regions Also theView has prism:ClearChildViewsRegionBehavior.ClearChildViews="True"].
Using ViewModel-First approach, when I remove a TabItem from the TabControl, I call a CloseThisViewModel() method on my theViewModel:
public void CloseThisViewModel(){
this._theView.CloseThisView();
this._theView = null;
}
and in theView:
public void CloseThisView(){
this.DataContext = null;
}
I manually call GarbageCollector:
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
I have a destructor/Finalizer in my ViewModel and this.Dispatcher.ShutdownStarted in my View. I do not have any unmanaged code in my View.
I observe that TheViewModel destructor is called after closing the tabItem.
Dispatcher.ShutdownStarted is only called when main application exits.
Could anyone provide inputs on the following:
Since I open/close many tabitems, I want to ensure that the unused usercontrols (my views) are not floating/dangling around. I know that corresponding viewmodels are properly disposed off. Also, I don't intend to close my main application ever.
Can there be a memory leak?
Is there a way to call Dispatcher.ShutdownStarted from outside UI Thread?
How can I verify, before application exits, that the view with a null reference are garbage collected?
Please let me know if I could provide more information.
Any help is highly appreciated.
I have a TabControl and I am creating a new scoped region manager for every tabItem which holds the same usercontrol (which has nested regions in it): regionManager.Regions["TAB_REGION"].Add(theView, null, true);
[I am not assigning any variable to the new scoped regionmanager. Also, theView is NonShared and is created for each tabItem and contains some regions Also theView has prism:ClearChildViewsRegionBehavior.ClearChildViews="True"].
Using ViewModel-First approach, when I remove a TabItem from the TabControl, I call a CloseThisViewModel() method on my theViewModel:
public void CloseThisViewModel(){
this._theView.CloseThisView();
this._theView = null;
}
and in theView:
public void CloseThisView(){
this.DataContext = null;
}
I manually call GarbageCollector:
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
I have a destructor/Finalizer in my ViewModel and this.Dispatcher.ShutdownStarted in my View. I do not have any unmanaged code in my View.
I observe that TheViewModel destructor is called after closing the tabItem.
Dispatcher.ShutdownStarted is only called when main application exits.
Could anyone provide inputs on the following:
Since I open/close many tabitems, I want to ensure that the unused usercontrols (my views) are not floating/dangling around. I know that corresponding viewmodels are properly disposed off. Also, I don't intend to close my main application ever.
Can there be a memory leak?
Is there a way to call Dispatcher.ShutdownStarted from outside UI Thread?
How can I verify, before application exits, that the view with a null reference are garbage collected?
Please let me know if I could provide more information.
Any help is highly appreciated.