I create games manager which could select different games in region using PRISM MEF. There is a static shell and dynamic content in "MainRegion". Each game is separated module(assembly) and it's allocated about 20-30 MB for each game, when i getting instance.
I have such components for each game:
- MainView [CreationPolicy.Shared]
- View1 [CreationPolicy.Shared]
- ViewN [CreationPolicy.Shared]
- MainViewModel [CreationPolicy.Shared]
- ViewModel1 [CreationPolicy.Shared]
- ViewModelN [CreationPolicy.Shared]
Each "View"(main, 1st, 2nd...) created by calling
_serviceLocator.GetInstance<MainView>();
Each "View" has the following property
[Import(AllowRecomposition = false)]
public MainViewModel ViewModel //example for MainView
{
get { return this.DataContext as MainViewModel; }
set { this.DataContext = value; }
}
When I want to change game I remove MainView
from MainRegion
, but it doesn't create a new instance because PartCreationPolicy
is set to Shared
, but if I use NonShared
it has a memory leak after the instance is removed.
How can I fix this memory leak in my application?