GridView memory leak (ScrollViewer event handler)

16 posts, 0 answers
  1. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 01 Apr 2013 Link to this post

    Hello. I have big problem. I have application with next structure: ... -> ScrollViewer -> Canvas -> ContentControls (many) -> GridView.

    When I remove one ContentControl with GridView from Canvas, GridView is still be in memory. It occurs because the gridView has SizeChangedEventHandler (see attached image).

    I deleted ScrollViewer from application and now gridView delete from memory.

    Full Call stack from attached image

    Telerik.Windows.Controls.GridView!Telerik.Windows.Controls.GridView.GridViewDataControl.EnsureInternalScrollControls() GridViewDataControl.cs
    Telerik.Windows.Controls.GridView!Telerik.Windows.Controls.GridView.GridViewDataControl.get_InternalScrollHost() GridViewDataControl.cs
    Telerik.Windows.Controls.GridView!Telerik.Windows.Controls.GridView.GridViewHeaderRow.MeasureOverride( Size ) GridViewHeaderRow.cs
    PresentationFramework!System.Windows.FrameworkElement.MeasureCore( Size )
    PresentationCore!System.Windows.UIElement.Measure( Size )
    PresentationFramework!System.Windows.Controls.Grid.MeasureCell( int,bool )
    PresentationFramework!System.Windows.Controls.Grid.MeasureCellsGroup( int,Size,bool,bool )
    PresentationFramework!System.Windows.Controls.Grid.MeasureOverride( Size )
    PresentationFramework!System.Windows.FrameworkElement.MeasureCore( Size )
    PresentationCore!System.Windows.UIElement.Measure( Size )
    PresentationFramework!System.Windows.Controls.ScrollViewer.MeasureOverride( Size )
    Telerik.Windows.Controls.GridView!Telerik.Windows.Controls.GridView.GridViewScrollViewer.MeasureOverride( Size ) GridViewScrollViewer.cs
    PresentationFramework!System.Windows.FrameworkElement.MeasureCore( Size )
    PresentationCore!System.Windows.UIElement.Measure( Size )
    PresentationFramework!System.Windows.Controls.Grid.MeasureCell( int,bool )
    PresentationFramework!System.Windows.Controls.Grid.MeasureCellsGroup( int,Size,bool,bool )
    PresentationFramework!System.Windows.Controls.Grid.MeasureOverride( Size )
    PresentationFramework!System.Windows.FrameworkElement.MeasureCore( Size )
    PresentationCore!System.Windows.UIElement.Measure( Size )
    PresentationFramework!System.Windows.Controls.Border.MeasureOverride( Size )
    PresentationFramework!System.Windows.FrameworkElement.MeasureCore( Size )
    PresentationCore!System.Windows.UIElement.Measure( Size )
    PresentationFramework!System.Windows.Controls.Control.MeasureOverride( Size )
    Telerik.Windows.Controls.GridView!Telerik.Windows.Controls.GridView.GridViewDataControl.MeasureOverride( Size ) GridViewDataControl.cs
    PresentationFramework!System.Windows.FrameworkElement.MeasureCore( Size )
    [Truncated]


    Can you help me?

    Thanks

  2. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 03 Apr 2013 Link to this post

    Hi Sergey,

    Thank you for the feedback.

    A grid in ScrollViewer will be measured with infinity and this may cause the problem. I would suggest checking Tips and Tricks topic. Could you set fixed width and height for your grid and let us know about the result? If the memory leak still occurs, please open a support ticket and attach your project there, so we can profile it on our end.
     
    Kind regards,
    Yordanka
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 03 Apr 2013 Link to this post

    Thanks. But I saw this Tips and Tricks, and I wrote the topic some weeks ago (http://www.telerik.com/community/forums/wpf/gridview/gridview-perfomance-in-canvas.aspx). How can I set fixed width and height in my situation? It works without ScrollViewer, but with Canvas ( Canvas will be measured with infinity too as was told in a topic). I think GridView subscribes for an event and then doesn't unsubscribe from it.
  5. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 04 Apr 2013 Link to this post

    Hi Sergey,

    You can set Width and Height for your RadGridView. Do you still get the memory leak in this case?
     
    Greetings,
    Yordanka
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 08 Apr 2013 Link to this post

    Hello. Yes I still get memory leak in this case.
  7. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 08 Apr 2013 Link to this post

    Hello Sergey,

    Could you open a support ticket and attach there a sample project which reproduces the memory leak? We will profile it on our end and will assist you further. Thank you in advance.
     
    Regards,
    Yordanka
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 08 Apr 2013 Link to this post

    Sorry, but I can't attach a sample project now. I need many time to do this.

    I can show problem in RadGridView source code (class - GridViewDataControl):
    internal void EnsureInternalScrollControls()
    {
    if (_internalScrollContentPresenter == null)
    {
    if (this.ItemsHost != null)
    {
    _internalScrollContentPresenter = this.ItemsHost.ParentOfType<ScrollContentPresenter>();
    }
    else if (_rowTrackingRoot != null)
    {
    if (_rowTrackingRoot.First != null && _rowTrackingRoot.First.Value != null)
    {
    GridViewRowItem row = _rowTrackingRoot.First.Value;
    _internalScrollContentPresenter = row.ParentOfType<ScrollContentPresenter>();
    }
    }
    if (_internalScrollContentPresenter != null)
    {
    _internalScrollContentPresenter.SizeChanged += new SizeChangedEventHandler(OnInternalScrollContentPresenterSizeChanged);
    }
    }
    ...
    }

    As you can see this class subscribe on SizeChanged event. It happened when one one of parents is ScrollContentPresenter. But when we need to delete RadGridView from memory we can't do it, because  we have reference (as event handler).

    I saw unsubscribing method only in OnApllyTemplate().


  9. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 09 Apr 2013 Link to this post

    Hello Sergey,

    Thank you for the details.

    We checked this method and in our latest version this code is different. Could you confirm version of the Telerik controls you are using? Could you download our latest official version - Q1 2013 SP1 and test your project with it?
     
    All the best,
    Yordanka
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 17 Jul 2014 in reply to Yordanka Link to this post

    Hi,

    This still seems to be a problem. I have a RadGridView in an auto-sized GroupBox, and it's not releasing when the window is closed (the containing View IS released). Setting a fixed width and height resolve the problem, but this is not ideal from an UI design perspective. Is there any way to have a dynamically sized grid and not leak memory?

    Thanks,
    Louis
  11. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Jul 2014 Link to this post

    Hello Louis,

    Most probably this auto-sized GroupBox container measures RadGridView with infinity. That is why setting a fixed width and height resolves the issue.

    I would not recommend you to define RadGridView (or any virtualized control) in such a container as it measures with infinity and the virtualization of the grid will be broken. Please take a look at our online documentation for additional information.

    Additionally, we fixed some memory leaks in the past two releases. Can you check if you still get the problem with our latest binaries?  

    Regards,
    Didie
    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.
     
  12. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 22 Jul 2014 in reply to Dimitrina Link to this post

    Hi Didie, 

    Yes, that is exactly the issue, as was described earlier in the thread. 

    I was aware of the Tips and Tricks, as it was also linked earlier in this post. However, not being able to put it in a Auto sizing Grid isn't a feasible restriction. How would you suggest implementing a grid that sizes with the available window if not using a container that measures infinity? It's not reasonable to constrain a grid to the least-supported-screen size when much bigger monitors are much more common. 

    I just tried the latest dev build (2014_2_0721_DEV_hotfix) and it's still an issue.

    Thanks,
    Louis

    P.S. For anyone else with this problem, memory does get freed if you are able to remove the GridView from the visual tree when the window is no longer needed (but this is a very ugly work-around).







  13. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 23 Jul 2014 Link to this post

    Hello,

    I am afraid I cannot suggest a solution to avoid measuring auto-sized RadGridView with infinity when placed in such a container.

    Regards,
    Didie
    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.
     
  14. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 23 Jul 2014 in reply to Dimitrina Link to this post

    Ok, thanks Didie. Can you push for a fix to the memory leak?

    Louis
  15. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 25 Jul 2014 Link to this post

    Hi Louis,

    I forwarded the case to the development team and they confirmed they are going to handle the case with the handler that is not detached.

    As to the memory leak, we are actually not able to prove such locally.  In case you can prove the leak in a demo solution, would you please send it to us?  That way we will check it further.

    Regards,
    Didie
    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.
     
  16. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 25 Jul 2014 in reply to Dimitrina Link to this post

    Hi Didie,

    I'm not sure how much effort it's going to be to reproduce in a demo solution, since the real scenario is quite complex using a tab manager and a custom Dependency Injection framework. I'll give it a try if I have some time.

    However, I'd guess that the handler that doesn't get detached is the source of the problem; this is likely the reason behind the recommendation to avoid infinite sized containers, as putting the grid in such a container seems to work fine except for the cleanup issue, and removing the Grid from the visual tree resolves that as well. I'd be happy to try a dev build version against our real app when the fix is available and confirm if it addresses the memory issue. 

    Thanks again,
    Louis
  17. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 25 Jul 2014 Link to this post

    Hi,

    Indeed, your comments seem reasonable. I will update the bug item with this information.

    Regards,
    Didie
    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.
     
Back to Top
UI for WPF is Visual Studio 2017 Ready