I am currently developing a WPF application using the Prism Library. In my application, I am utilizing the ScopedRegionManager in SpecView to manage different views. Some of these views hold unmanaged resources, and I need to ensure these resources are properly disposed of when the view is navigated away from. Typically, I would call the Dispose method to clean up these resources.
However, I have encountered a problem: when navigating away from SpecView which has the ScopedRegion, the OnNavigatedFrom method of the child view holding the unmanaged resources is not called. As a result, I have no indication that the view has left, and the unmanaged resources are retained in memory, causing a memory leak.
Currently, my solution is to call the following code in the OnNavigatedFrom method of each layer’s ViewModel:
var parameter = new NavigationParameters();
ScopedRegionManager.RequestNavigate("AlgRegion",
nameof(LeavingView), NavigationFinished,
parameter);
wentao cheng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.