I am working on a WPF project. It uses the Prism's IOC container, RegionManager and EventAggregator.
I bind the views and view models with the autowire feature of Prism. So I navigate just with RegionName and view as below
_regionManager.RequestNavigate(
RegionName,
NameOf(ParentContentView))
ParentContentView has 3 different child controls which comminucate with each others by using EventAggregator feature of the Prism. The program tries to load this ParentContentView from scratch every time.
ParentContentView has been registered to the our IOC as below
builder.
RegisterTypeForNavigation(Of ParentContentView)(
Nameof(ParentContentView))
After leaving this ParentContentView by using regionmanager.RequestNavigate() method the ParentContentView is still alive. I inspected it on dotMemory application of JetBrains.
Every open and leave operation adds an object to the memory. For example if I open and close ParentContentView 4 times then object counts of ParentContentView will be 4. In a somehow prism keeps it alive.
I implemented IRegionMemberLifetime in View code behind and the code as below
public partial class ParentContentView : IRegionMemberLifetime
{
public ParentContentView()
{
InitializeComponent();
}
public bool KeepAlive
=> false;
}
I debugged the code and it really hits KeepAlive property but it did not solve the problem. I also tried to remove the event references of child objects. I also unsubscribe the eventaggregator events. none of them did not work for me.
Any help would be appreciated.