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
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.
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.
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.
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().
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.
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
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
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).
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
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
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
Indeed, your comments seem reasonable. I will update the bug item with this information.
Regards,
Didie
Telerik