Hello dear Telerik Forum.
I have a memory leak problem, where opening views add up in memory, because they are still somehow referenced and thus not GCed.
I've implemented Prism and Telerik both in my application. I've also implemented the ScopedRegionNavigationContentLoader, the RegionManagerAwareBehavior (and everything else required to open views in new tabs) from Brian (Prism) and the RadTabbedWindow in my MainWindow. So when I execute RequestNavigate from the MainWindow I open new Tabs.
Following happens:
When I execute RequestNavigate commands from the MainWindow I successfully open a new tab which then builds the view, existing of multiple subviews. This works correct so far.
Now when I close the RadTabItems the Views still stay in the memory. It seems there are still references in the RegionManager about the once spawned Regions/Views. Those add up when using the application over hours.
So my question is:
How do I unload the Region/View in the RegionManager of the MainWindow when I close the tabs?
I'm looking for a clean and global solution, where I dont have to implement code in every class.
Extra information:
- There is one RegionManager in the MainWindow, which manages all Tabs and so.
- Each Subview gets its own new RegionManager instance.
I found myself an answer.
Though It needs to be adapted to the objects being used.
For anyone else seeing this in the future I refer to this link:
https://brianlagunas.com/using-the-xamtabcontrol-as-a-prism-region-and-closing-tab-items/
I replaced the xamtabcontrol objecct with the RadTabbedWindow.
And the "TabItemEx" Objects with RabTabControl
I have one question though.
When closing a RadTabItem the SelectedItem/SelectedValue/SelectedContent is still set to the active tab. Which is logical.
I need to somehow access the "Closing RadTabItem", when I click on the X (close button) because I want to unload this Tabs content.
As of right now my solution unloads the view of the "SelectedItem/SelectedValue/SelectedContent", but it's the wrong one, leading to an exception when closing a second tab, because it still is set to the now unloaded view which doesn't exist anymore, because as mentioned, it's unloaded
Is there a property to access the "Unloading-RadTabItem"? If not, is there a way Telerik can implement such a property that I can access it and thus unload the view without doing some acrobatic magic?
May I ask if you could try the PreviewTabClosed and Tab closed events of the RadTabControl control? These events will allow you to intercept the close operation of a RadTabItem element.
More information on these events can be found at the following link:
WPF TabControl - Events - Telerik UI for WPF