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

[Solved] RadGridView releasing memory?

2 Answers 180 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jim
Top achievements
Rank 1
Jim asked on 23 Jun 2009, 05:12 PM
The garbage collector doesn't appear to be able to free my RadGridViews once I set their ItemsSource to an ObservableCollection.

Perhaps I am not really executing things correctly so I am hoping you can set me straight on this.  I created a very simple project that demonstrates my problem.  Unfortunately even a simple project is a lengthy post, so I appologize in advance for that.

btw: I am using the silverlight 3 controls, version 2009.1.529.1020

The project simply adds a UserControl that contains a RadGridView which binds to a very simple two property class.  A button allows you to add one of these UserControls and another button removes it.  Theoritically if you punch add, add, add, then remove, remove, remove, then garbage collect (also a button) you should be able to fire up WinDBG and notice that there are no instances of the class TestGarbage.AGridView in the heap. Unfortunately this is not what I see... HELP?

Here are the !DumpHeap -type TestGarbage.AGridView results from doing the previously mentioned steps:
0:026> .loadby sos coreclr 
0:026> !dumpheap -type TestGarbage.AGridView 
... 
 Address       MT     Size 
0482f6a8 06bd70a4       84      
048e8cec 06bd70a4       84      
049e6f60 06bd70a4       84      
total 3 objects 
Statistics: 
      MT    Count    TotalSize Class Name 
06bd70a4        3          252 TestGarbage.AGridView 
 

And the !gcroot on the first item 0482f6a8
0:026> !gcroot 0482f6a8 
Note: Roots found on stacks may be false positives. Run "!help gcroot" for 
more info. 
Scan Thread 8 OSTHread f9c 
Scan Thread 24 OSTHread 10d4 
Scan Thread 25 OSTHread 7ec 
DOMAIN(02E9F5A8):HANDLE(Pinned):6be12f8:Root:  05814260(System.Object[])-> 
  04820230(System.Collections.Generic.Dictionary`2[[System.IntPtr, mscorlib],[System.Object, mscorlib]])-> 
  05818170(System.Collections.Generic.Dictionary`2+Entry[[System.IntPtr, mscorlib],[System.Object, mscorlib]][])-> 
  048799b4(MS.Internal.ManagedObjectReference)-> 
  0486cb40(Telerik.Windows.Data.FieldFilterDescription)-> 
  0486cbe8(Telerik.Windows.Data.RadObservableCollection`1[[Telerik.Windows.Data.FilterDescriptor, Telerik.Windows.Data]])-> 
  0486ccc4(System.Collections.Specialized.NotifyCollectionChangedEventHandler)-> 
  0486ccac(System.Object[])-> 
  0486cc8c(System.Collections.Specialized.NotifyCollectionChangedEventHandler)-> 
  048656f4(Telerik.Windows.Controls.GridView.FilteringDropDown)-> 
  048659a8(System.Windows.Controls.Grid)-> 
  04865608(System.Windows.Controls.Grid)-> 
  04865aa4(System.Windows.Controls.Grid)-> 
  0486351c(Telerik.Windows.Controls.GridView.GridViewHeaderCell)-> 
  04830a84(Telerik.Windows.Controls.RadGridView)-> 
  0484574c(System.Windows.Controls.Grid)-> 
  0482f6a8(TestGarbage.AGridView)-> 


The code follows ( I can also send a .RAR file that contains the project if that helps)

XAML for User Control that has the grid in it:
<UserControl x:Class="TestGarbage.AGridView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    Loaded="UserControl_Loaded"
    <Grid x:Name="LayoutRoot" Background="White"
        <telerikGrid:RadGridView x:Name="cGridView" > 
            <telerikGrid:RadGridView.Columns> 
                <telerikGrid:GridViewDataColumn HeaderText="ID" DataMemberBinding="{Binding ID}" Width="Auto"/> 
                <telerikGrid:GridViewDataColumn HeaderText="Name" DataMemberBinding="{Binding Name}" Width="Auto" /> 
            </telerikGrid:RadGridView.Columns> 
        </telerikGrid:RadGridView> 
    </Grid> 
</UserControl> 
 

.CS for same User Control
using System; 
using System.Collections.ObjectModel; 
using System.Windows.Controls; 
using System.Windows; 
 
namespace TestGarbage 
    public partial class AGridView : UserControl 
    {        
        public AGridView() 
        { 
            InitializeComponent();           
        } 
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e) 
        { 
            var coll = new ObservableCollection<Simple>(); 
            coll.Add( new Simple { Name = "First"ID = "1" }); 
            coll.Add(new Simple { Name = "Second"ID = "2" }); 
            cGridView.ItemsSource = coll
        }        
    } 

.XAML for MAINPAGE in a new application
<UserControl x:Class="TestGarbage.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:local="clr-namespace:TestGarbage" 
    Width="400" Height="300"
    <StackPanel x:Name="LayoutRoot" Background="White" Orientation="Vertical"
 
        <Button Content="Add Control" Click="AddOne" /> 
        <Button Content="Remove OK" Click="RemoveOK" /> 
         
        <Button Content="Collect Garbage" Click="OnCollect" /> 
        <StackPanel x:Name="cStack" Orientation="Vertical" /> 
    </StackPanel> 
</UserControl> 

.CS for MAINPAGE
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using System.Collections.ObjectModel; 
 
namespace TestGarbage 
    public partial class MainPage : UserControl 
    { 
        public MainPage() 
        { 
            InitializeComponent(); 
        } 
 
        private void  
        AddOne(object sender, RoutedEventArgs e) 
        { 
            var control = new AGridView(); 
 
            cStack.Children.Add( control ); 
        } 
 
        private void  
        OnCollect(object sender, RoutedEventArgs e) 
        { 
            GC.Collect(); 
            GC.WaitForPendingFinalizers();  
        } 
 
        private void RemoveOK(object sender, RoutedEventArgs e) 
        { 
            cStack.Children.RemoveAt( cStack.Children.Count -1 ); 
             
        } 
    } 


2 Answers, 1 is accepted

Sort by
0
Hristo Deshev
Telerik team
answered on 26 Jun 2009, 01:28 PM
Hello Jim,

I have reproduced and confirmed the leak -- thanks for the awesome report. I am still not sure why it is happening. The gcroot report tells us that there is a FieldFilterDescription object hung in memory that keeps a reference to a GridViewHeaderCell, which in turn keeps the RadGridView object in memory.

I find two things odd:
  • That leak does not happen in Silverlight 2.
  • The object keeping a reference to the FieldFilterDescription object is not a Telerik-created one -- it looks like a Silverlight-internal object.
I have a slight suspicion we might be dealing with a Silverlight 3 popup-related leak (Hey, it's still in beta!) as the filtering UI creates a popup control. We will be investigating that in greater detail.

In the mean time, the best I can offer is to disable filtering on RadGridView. That eliminates the leak.
Greetings,
Hristo Deshev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jim
Top achievements
Rank 1
answered on 26 Jun 2009, 02:46 PM
Great! The good news is I don't need this fixed until after Silverlight 3 is released :).  Mostly I wanted to figure out if there was something I was doing incorrectly.  I am confident you guys will either fix it (if it is yours) or that it will be resolved by the silverlight team at MS.
Tags
GridView
Asked by
Jim
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
Jim
Top achievements
Rank 1
Share this question
or