This is a migrated thread and some comments may be shown as answers.

Dynamically loading user controls in RadPane

4 Answers 387 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 21 Feb 2012, 07:08 AM
Hello,

What is the correct pattern for dynamically loading new user controls in a RadPane window?

I have a RadRibbonView that I'm using and depending on the button clicked - I dynamically load a new user control into a targeted RadPane by assigning the new user control to the Content property.  Pretty basic and it seems to work.  The problem is that the previous user control never gets unloaded or free'd up and my memory usage sky rockets as you click the buttons and new controls are loaded.

I have a very simple setup inside a RadSplitContainer:
<telerik:RadSplitContainer telerik:ProportionalStackPanel.RelativeSize="700,200">
<telerik:RadPaneGroup x:Name="mainDataPaneGroup">
<telerik:RadPane CanUserClose="False" x:Name="mainDataPane">
<local:Summary></local:Summary>
</telerik:RadPane>
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>

In the code behind I have a reference to the RadPane and I assign the new UserControl to the content of the RadPane:
public static void ReloadMainDataPane(UserControl control)
{
            MainDataPane.Content = control;                       
 }

The behavior is correct and the new user control is loaded into the RadPane, however it seems that the previous UserControl that was in there is never actually unloaded and certainly doesn't ever get free'd from memory (even calling GC.Collect).

Is there something I have to do to unload the previous Pane from the RadPaneGroup?  I'm not sure what the correct pattern is here to make sure the previous UserControl is properly unloaded from memory...

Thanks!

Chris

4 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 23 Feb 2012, 04:31 PM
Hello,

Changing the Content property of the RadPane is the correct way to load different contents for the panes and shouldn't cause any memory leaks. A problem could exist if you hold a reference to the old content or it was declared in XAML.
There is one memory leak in the Docking control we are aware of - if you are removing the whole pane and it was the last one in the group, it is not destroyed before you add another pane in this group. If you are removing panes somewhere the could also be the problem.

As we are not aware of a memory leak in the case you described, it would be of great help if you could prepare us a sample project that demonstrates the problem. This way we will see how you initially load the panes, how you change the content of the panes, etc.

All the best,
Miroslav Nedyalkov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Chris
Top achievements
Rank 1
answered on 23 Feb 2012, 05:38 PM
Thanks for the response Miroslav!

Both the original user control that was loaded and the new one that I'm trying to load are declared in XAML.  It's actually the same user control - I'm just creating a new instance of it in the code behind and reloading it in the pane by assigning that new UserControl object to the Content property (eventually I will want to load other/different user controls though if I can get past this problem).  Is there a known issue with the control being declared in XAML and then assigned to the Content property of the pane? (or something I need to do in order to free any lingering references to the old control).  I'm not doing any other operations against the group or pane - simply assigning a new UserControl object to the Content property.

Thanks!

Chris


0
Miroslav Nedyalkov
Telerik team
answered on 27 Feb 2012, 01:25 PM
Hello Chris,

There is no known issue for this scenario and there is no additional operations you need to do - it should work property. Could please send us a sample project that demonstrates this memory leak? This way will be able investigate the problem further and either help you resolve it or fix the issue.

Kind regards,
Miroslav Nedyalkov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Chris
Top achievements
Rank 1
answered on 13 Mar 2012, 09:07 AM
This was an issue in my code.  I had a lingering reference to an event on a Tree control that was still active.

Solution was to remove the event in the Unloaded() event.

Thanks!


Tags
Docking
Asked by
Chris
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Chris
Top achievements
Rank 1
Share this question
or