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

Why not dispose of RadPanes? Memory leak issue.

5 Answers 427 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 18 May 2011, 02:33 PM
Through forum searches I've realized that you never actually dispose of a Pane, rather make IsHidden to True upon "close," either from a floating ToolWindow or when it's in its docked state.

This is very aggravating, and since I realize this is probably not something you'll change, I'm wondering why did you decide this was appropriate and how can I as a developer handle the resulting memory leaks? How am I to handle View/Viewmodel disposal when a user closes a Pane if the pane continues to exist with a strong reference via its Content and/or DataContext?

If there was even a proper event or argument that would signify a close, that would be fine - I could kill the view/vm myself. But, neither VisibilityChanged nor PaneStateChanged fire on close, and I don't see anything during Pane_Unloaded that would say for certain the pane is closing and not doing something like changing docking states (when you undock or re-dock a pane, its IsHidden is false during the transition, so that doesn't help at all).

TL;DR: Any thoughts on how to know when a pane is closed?

5 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 25 May 2011, 09:19 AM
Hello Greg,

You could use the PreviewClose and Close events of the Docking control. We decided to put the events to the Docking control as it is easer to handle events at the element which is not moved/changed during the application lifetime.

We decided to not remove the panes by default, because it is easier to remove them if you need to instead of inserting them back if you want to leave them in the Docking control. We are planning to add property to the RadDocking control for this.

Here is an example how to achieve this:
public class DockingExtensions
{
    public static bool GetRemovePanesWhenClosed(DependencyObject obj)
    {
        return (bool)obj.GetValue(RemovePanesWhenClosedProperty);
    }
  
    public static void SetRemovePanesWhenClosed(DependencyObject obj, bool value)
    {
        obj.SetValue(RemovePanesWhenClosedProperty, value);
    }
  
    public static readonly DependencyProperty RemovePanesWhenClosedProperty =
        DependencyProperty.RegisterAttached("RemovePanesWhenClosed", typeof(bool), typeof(DockingExtensions), new PropertyMetadata(false, OnRemovePanesWhenClosedPropertyChanged));
  
    private static void OnRemovePanesWhenClosedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var newValue = (bool)e.NewValue;
        var dock = d as RadDocking;
  
        if (dock != null)
        {
            if (newValue)
            {
                dock.PreviewClose += dock_PreviewClose;
            }
            else
            {
                dock.PreviewClose -= dock_PreviewClose;
            }
        }
    }
  
    private static void dock_PreviewClose(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
    {
        foreach (var pane in e.Panes)
            pane.RemoveFromParent();
  
        e.Handled = true;
    }
}

Having this attached property you just need to set it to the Docking control:
<telerik:RadDocking local:DockingExtensions.RemovePanesWhenClosed="True">

Hope this helps.

Kind regards,
Miroslav Nedyalkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cody
Top achievements
Rank 1
answered on 24 Oct 2011, 07:53 PM
Has this been added to the docking control yet?  I am using version 2011.2.920.1040.
0
Miroslav Nedyalkov
Telerik team
answered on 25 Oct 2011, 08:09 AM
Hi Cody,

This feature is not added to the Docking control yet.

Regards,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Adiel
Top achievements
Rank 1
answered on 16 Sep 2014, 04:59 AM
We have issues with this behavior. 
Any news on removing RadPane? 
0
Kalin
Telerik team
answered on 18 Sep 2014, 01:12 PM
Hi Meir,

If you'd need to dispose a Pane you would have to manually call its RemoveFromParent method - this behavior is not implemented in control. However you can easily do that by simply hook to the PreviewClose event of the control and call the RemoveFromParent method of the Pane. However as this thread is really old - if you face any particular issue with the control, I'll kindly ask you to open a support ticket with detailed explanation of the issue and sample project attached if possible.

Hope this helps.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Docking
Asked by
Greg
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Cody
Top achievements
Rank 1
Adiel
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or