How to unload Prism Views from closed RadTabItems?

0 Answers 16 Views
TabbedWindow TabControl
Anastasios
Top achievements
Rank 1
Anastasios asked on 26 Oct 2023, 02:39 PM | edited on 26 Oct 2023, 02:42 PM

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.

 

Anastasios
Top achievements
Rank 1
commented on 26 Oct 2023, 03:45 PM

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

Stenly
Telerik team
commented on 27 Oct 2023, 01:29 PM | edited

I am happy to hear that you found a solution to this question and that you took the time to share it as well.
Anastasios
Top achievements
Rank 1
commented on 27 Oct 2023, 01:33 PM | edited

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?

Stenly
Telerik team
commented on 27 Oct 2023, 03:00 PM

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

No answers yet. Maybe you can help?

Tags
TabbedWindow TabControl
Asked by
Anastasios
Top achievements
Rank 1
Share this question
or