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

GridView memory leak (ScrollViewer event handler)

15 Answers 191 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 1
Sergey asked on 01 Apr 2013, 09:54 AM

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

15 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 03 Apr 2013, 12:57 PM
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.

0
Sergey
Top achievements
Rank 1
answered on 03 Apr 2013, 06:01 PM
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.
0
Yordanka
Telerik team
answered on 04 Apr 2013, 01:33 PM
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.

0
Sergey
Top achievements
Rank 1
answered on 08 Apr 2013, 06:52 AM
Hello. Yes I still get memory leak in this case.
0
Yordanka
Telerik team
answered on 08 Apr 2013, 12:18 PM
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.

0
Sergey
Top achievements
Rank 1
answered on 08 Apr 2013, 01:00 PM
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().


0
Yordanka
Telerik team
answered on 09 Apr 2013, 11:20 AM
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.

0
Louis
Top achievements
Rank 1
answered on 17 Jul 2014, 06:33 PM
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
0
Dimitrina
Telerik team
answered on 22 Jul 2014, 08:50 AM
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.
 
0
Louis
Top achievements
Rank 1
answered on 22 Jul 2014, 09:41 PM
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).







0
Dimitrina
Telerik team
answered on 23 Jul 2014, 12:27 PM
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.
 
0
Louis
Top achievements
Rank 1
answered on 23 Jul 2014, 02:59 PM
Ok, thanks Didie. Can you push for a fix to the memory leak?

Louis
0
Dimitrina
Telerik team
answered on 25 Jul 2014, 02:57 PM
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.
 
0
Louis
Top achievements
Rank 1
answered on 25 Jul 2014, 03:28 PM
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
0
Dimitrina
Telerik team
answered on 25 Jul 2014, 03:36 PM
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.
 
Tags
GridView
Asked by
Sergey
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Sergey
Top achievements
Rank 1
Louis
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or