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

RadGridView ItemSource Binding being cleared does not free up memory.

3 Answers 325 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 30 Jan 2015, 03:27 PM
Hi Guys,

We have a pretty large app that relies on many of your components. We have become aware of Memory leaks in our products that over time crash the application. Every time we try to track down where they are coming from it always ends up being in the unmannaged memory that ties to your objects. 

One of the problems we have is with the Telerik RadGridView. We store a lot of data into these grid views and when the user clears the data in the grid views we expect the memory to be free'd up and not to keep stacking.

I went ahead and made a sample application to show you guys. All i'm doing is adding rows to the grid via a ObservalbleCollection<string> bound to the ItemSource and then clearing that ObservableCollection. In this sample application however if I clear multiple times it does in fact release the memory. I'm not sure why it would take multiple clear calls especially since I am calling GC.Collect() and GC.WaitForPendingFinalizers in the clear function for testing.
In our actual application that memory never disposes and ramps up every time we load new data until we run out of memory and I will do my best to reproduce this in another sample program.


In our actual application that memory never disposes and ramps up every time we load new data until we run out of memory and I will do my best to reproduce this in another sample program.

We are updated to the newest Silverlight and Telerik versions.

Here is the xaml and code behind for the sample project.

MainPage.Xaml

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
x:Name="UserControlCodeSummary"
x:Class="SilverlightApplication1.MainPage"
d:DesignHeight="317"
d:DesignWidth="1082">
    <StackPanel>
        <Button
            Height="18"
            Name="AddData"
            Click="Add_Data_Click"
            Content="Add Data"
            >
        </Button>
        <Button
            Height="18"
            Name="ClearData"
            Click="Clear_Click"
            Content="Clear Data"
            >
        </Button>
        
        <telerik:RadGridView
         x:Name="DatagridHCPCS"
EnableColumnVirtualization="False"
EnableRowVirtualization="False">
        </telerik:RadGridView>
        </StackPanel>
</UserControl>


MainPage.xaml.cs


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.Windows.Data;
using System.Collections.ObjectModel;
using Telerik.Windows;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {

        private ObservableCollection<string> itemSource = new ObservableCollection<string>();
        public MainPage()
        {
            InitializeComponent();
            this.DatagridHCPCS.ItemsSource = itemSource;
        }

        private void Add_Data_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < 15; i++)
            {
                itemSource.Add("123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789");
            }
        }

        private void Clear_Click(object sender, RoutedEventArgs e)
        {
            itemSource.Clear();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }
}

















3 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 30 Jan 2015, 04:10 PM
After Messing with the project to make it look more like our project. I was able to reproduce exactly what our project was doing in this code.

The difference is auto Generate Columns is off so the ItemSource bindings don't bind directly to the column and for some reason when ItemSource is cleared the objects are not being garbage collected ever no matter how many clears I do.

Here is the updated code.

MainPage.Xaml
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
x:Name="UserControlCodeSummary"
x:Class="SilverlightApplication1.MainPage"
d:DesignHeight="317"
d:DesignWidth="1082">
    <StackPanel>
        <Button
            Height="18"
            Name="AddData"
            Click="Add_Data_Click"
            Content="Add Data"
            >
        </Button>
        <Button
            Height="18"
            Name="ClearData"
            Click="Clear_Click"
            Content="Clear Data"
            >
        </Button>
        
        <telerik:RadGridView
         x:Name="DatagridHCPCS"
                AutoGenerateColumns="False"
EnableColumnVirtualization="False"
EnableRowVirtualization="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn
x:Name="Strings"
Header="Strings" 
/>                    
                </telerik:RadGridView.Columns>
        </telerik:RadGridView>
        </StackPanel>
</UserControl>


MainPage.xaml.cs

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.Windows.Data;
using System.Collections.ObjectModel;
using Telerik.Windows;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;

namespace SilverlightApplication1
{
    [Export]
    public partial class MainPage : UserControl
    {

        private ObservableCollection<string> itemSource = new ObservableCollection<string>();
        public MainPage()
        {
            InitializeComponent();
            this.DatagridHCPCS.ItemsSource = itemSource;
        }

        private void Add_Data_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < 15; i++)
            {
                itemSource.Add("123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789");
            }
        }

        private void Clear_Click(object sender, RoutedEventArgs e)
        {
            itemSource.Clear();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }
}










0
David
Top achievements
Rank 1
answered on 30 Jan 2015, 04:33 PM
I created a support ticket for this issue with the code project zipped and attached to it. 

The support ticket # is 902160
0
Nick
Telerik team
answered on 02 Feb 2015, 03:12 PM
Hello David,

I have replied to the support ticket. 

The GridView in the sample project is placed in a stack panel which means it is measured with infinity(GridView needs an exact number to be measured with in order for the UI virtualization to take any effect), hence it creates rows for every single item in the ItemsSource. In this case, a high memory consumption is expected. Still clearing the items source releases the memory. 

Would it be possible to provide some more details about your scenario. What is the exact binaries version you are using. The support info indicates 2014.3.1202. is that correct? What is the OS version in which you are observing the problem?
Furthermore, a snapshot from a memory profiler would be very helpful in the process of finding the source of the problem and providing a solution. 
 


Regards,
Nick
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Nick
Telerik team
Share this question
or