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

Dispose of GridView Rows

10 Answers 176 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 12 Jan 2011, 04:43 PM
I'm using the RadGridView to display some nested data and am noticing some memory issues.  I am also using the RadDataPager and when I change pages the gridview rows are not being disposed of and memory just keeps increasing for each row I expand.  Is there any way to get the rows to be disposed of when a page is changed?  I have tried row virtualization but that doesn't seem to work either.  Here is my xaml for the grid:

 

 

 

<Grid x:Name="gridSearch" HorizontalAlignment="Left" Canvas.Left="30" Canvas.Top="8" Visibility="Collapsed" MaxWidth="981">

 

 

 

 

<Grid.RenderTransform>

 

 

 

 

<TransformGroup>

 

 

 

 

<ScaleTransform ScaleX="1" ScaleY="1" />

 

 

 

 

<SkewTransform/>

 

 

 

 

<RotateTransform/>

 

 

 

 

<TranslateTransform/>

 

 

 

 

</TransformGroup>

 

 

 

 

</Grid.RenderTransform>

 

 

 

 

<Grid.RowDefinitions>

 

 

 

 

<RowDefinition Height="Auto"/>

 

 

 

 

<RowDefinition Height="610"/>

 

 

 

 

<RowDefinition Height="Auto"/>

 

 

 

 

</Grid.RowDefinitions>

 

 

 

 

<telerik:RadDataPager Grid.Row="0"

 

 

 

x:Name="radDataPagerTop"

 

 

 

AutoEllipsisMode="None"

 

 

 

PageSize="10"

 

 

 

MaxWidth="981"

 

 

 

DisplayMode="FirstLastPreviousNextNumeric" PageIndexChanged="radDataPagerTop_PageIndexChanged" GotFocus="radDataPagerTop_GotFocus" MouseLeftButtonDown="radDataPagerTop_MouseLeftButtonDown">

 

 

 

 

</telerik:RadDataPager>

 

 

 

 

 

<TeleGrid:RadGridView x:Name="sgNameSearch" EnableColumnVirtualization="False" FontSize="10"

 

 

 

EnableRowVirtualization="False" Visibility="Collapsed" MaxHeight="610" Grid.Row="1"

 

 

 

MaxWidth="981" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" BorderThickness="0"

 

 

 

ScrollViewer.HorizontalScrollBarVisibility="Auto"

 

 

 

IsFilteringAllowed="True"

 

 

 

ShowGroupPanel="True"

 

 

 

d:LayoutOverrides="GridBox"

 

 

 

telerik:StyleManager.Theme="Office_Black"

 

 

 

ScrollMode="RealTime" Background="LightGray"

 

 

 

RowDetailsTemplate="{StaticResource NameSearchDetailTemplate}" Height="610" GroupPanelStyleName="EditSettingsGridViewGroupPanelStyle" >

 

 

 

 

<TeleGrid:RadGridView.Columns>

 

 

 

 

<telerik:GridViewToggleRowDetailsColumn UniqueName="ToggleColumn" />

 

 

 

 

<Controls:ConfigurableGridViewDataColumn UniqueName="MugImage" IsConfigurable="False" Header="Image" CellTemplate="{StaticResource imgMugRowTemplate}" DataFormatString="imgMugRowTemplate" />

 

 

 

 

<Controls:ConfigurableGridViewDataColumn UniqueName="Notice" IsConfigurable="False" Header="" Width="45" >

 

 

 

 

<TeleGrid:GridViewDataColumn.CellTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<Image x:Name="imgNotice" IsHitTestVisible="{Binding HasOpenNotice}" Visibility="{Binding HasOpenNotice, Converter={StaticResource OpenNoticeConverter}}" Stretch="Fill" Height="18" Width="18" Source="../images/Asterik.png" />

 

 

 

 

</DataTemplate>

 

 

 

 

</TeleGrid:GridViewDataColumn.CellTemplate>

 

 

 

 

</Controls:ConfigurableGridViewDataColumn>

 

 

 

 

<TeleGrid:GridViewDataColumn Header="Last Name" DataMemberBinding="{Binding LastName}" />

 

 

 

 

<TeleGrid:GridViewDataColumn Header="First Name" DataMemberBinding="{Binding FirstName}" />

 

 

 

 

<TeleGrid:GridViewDataColumn Header="Middle" DataMemberBinding="{Binding MiddleName}" />

 

 

 

 

<TeleGrid:GridViewDataColumn Header="Name Suffix" DataMemberBinding="{Binding NameSuffixCode}" />

 

 

 

 

<TeleGrid:GridViewDataColumn Header="Sex" DataMemberBinding="{Binding Sex}" />

 

 

 

 

<TeleGrid:GridViewDataColumn Header="Race" DataMemberBinding="{Binding Race}" />

 

 

 

 

</TeleGrid:RadGridView.Columns>

 

 

 

 

</TeleGrid:RadGridView>

 

 

 

 

<telerik:RadDataPager Grid.Row="2"

 

 

 

x:Name="radDataPagerBottom"

 

 

 

AutoEllipsisMode="None"

 

 

 

PageSize="10"

 

 

 

MaxWidth="981"

 

 

 

DisplayMode="FirstLastPreviousNextNumeric">

 

 

 

 

</telerik:RadDataPager>

 

 

 

 

</Grid>

 

10 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 17 Jan 2011, 09:03 AM
Hi Dan,

We will investigate the problem and contact you as soon as possible. Will it possible to send us the source of your application so that we can pinpoint the problem more accurately. 


Kind regards,
Milan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Dan
Top achievements
Rank 1
answered on 17 Jan 2011, 08:14 PM
Thanks Milan.  Unfortunately I can't give you the full source of the app due to company restrictions but I can give you an idea of what is going on behind the scenes.  There is functionality that stores the datacontext of rows that are expanded into a static generic list.  This list only stores 5 rows at a time though like so:

void StoreRecentCase(GridViewRowDetailsEventArgs e)
        {
            int caseID = Convert.ToInt32(BindingExpressionHelper.GetValue(e.Row.DataContext, "caseid"));
            string caseNumber = BindingExpressionHelper.GetValue(e.Row.DataContext, "casenumber").ToString();
            RecentCase.Add(new RecentCase { CaseID = caseID, CaseLink = caseNumber, CaseDataContext = e.Row.DataContext });
        }


        private static List<RecentCase> RecentCases
        {
            get
            {
                if(!SessionManager.Session.ContainsKey("RecentCases"))
                    SessionManager.Session.Add("RecentCases", new List<RecentCase>());
                return (List<RecentCase>)SessionManager.Session["RecentCases"];
            }
        }

     public static void Add(RecentCase recentCase)
        {            
            //look for case with identical caseid..if exists then remove it and add the new case to the top
            RecentCase identicalCase = RecentCases.Where(rc => rc.CaseID == recentCase.CaseID).FirstOrDefault();
            if (identicalCase == null)
            {
                RecentCases.Insert(0, recentCase);
                if (RecentCases.Count > 5)
                    RecentCases.RemoveAt(5);
            }
        }

These static references are probably at fault for keeping some of the gridview rows in memory but once they are removed from the static list they should be freed up in theory.  However, even when I comment out this functionality the memory doesn't seem to free itself.  Each time I expand a row the memory increases an additional 10 mb and never decreases back to the inital usage level even after I change pages in the datapager.  Can you give me some pointers of things I should look for to make sure that rows get disposed of properly?  Ideally, the row would be disposed of right when it is no longer on the page anymore.

0
Milan
Telerik team
answered on 18 Jan 2011, 02:52 PM
Hello Dan,

Unfortunately I cannot reproduce the problem. Have you trier using ANTS profiler from Red Gate to determine what elements is holding onto the grid rows? Does the problem still occur is you remove ConfigurableGridViewDataColumn? 


Best wishes,
Milan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Dan
Top achievements
Rank 1
answered on 24 Jan 2011, 10:05 PM
OK I have greatly simplified my project and am able to recreate the problem with the same basic structure that my project currently has.  When the site opens you will be on Page 1 which has the gridview on it.  If you expand a bunch of rows and click between pages you will see that the memory usage increases quite a bit pretty quickly but never gets released back to the original level even when you leave the page and click on the page 2 link.  I got the memory usage all the way up to 350k by continually expanding rows and then clicking between pages on page 1 and then going back and forth between Page 1 and Page 2.  I have tried to add in as much disposal logic as I can but I can't see where the issue is coming from at this point.  I have a solution zipped up that I can send you if you let me know how to send it to you.
0
Dan
Top achievements
Rank 1
answered on 25 Jan 2011, 11:31 PM
I have also noticed an issue with the GridViewColumns that use cell templates.  I'm not using inline templates per the silverlight memory leak data template issue but the memory leaks still persist.  I'm using WinDbg and get the following:
DOMAIN(08F6DD38):HANDLE(Pinned):47712f8:Root:  074ed240(System.Object[])->
  065081c0(SilverlightApplication1.MainPage)->
  20def104(System.Windows.SizeChangedEventHandler)->
  20def0d4(System.Object[])->
  06a6dd1c(System.Windows.SizeChangedEventHandler)->
  06a6da88(Telerik.Windows.Controls.GridView.GridViewScrollViewer)->
  159b8470(Telerik.Windows.Controls.RadGridView)->
  159b8d9c(System.Collections.Generic.Dictionary`2[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]])->
  159bac70(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]][])->
  15968fe0(Telerik.Windows.Controls.GridView.GridViewRow)->
  1596c51c(Telerik.Windows.Controls.GridView.DetailsPresenter)->
  15969b98(Telerik.Windows.Controls.GridView.SelectiveScrollingGrid)->
  15969dd0(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
  1596bd6c(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
  1596cd6c(System.Windows.Controls.Border)->
  1596ce44(System.Collections.Generic.Dictionary`2[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]])->
  1596ce90(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]][])->
  159b179c(Telerik.Windows.Controls.GridView.SelectiveScrollingGrid+BindingHelperProxy)->
  159b1a20(System.Collections.Generic.Dictionary`2[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]])->
  159b1a6c(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]][])->
  159b1a0c(MS.Internal.ModifiedValue)->
  159b18ec(System.Windows.Data.BindingExpression)->
  065fc2c8(Telerik.Windows.Controls.GridView.GridViewScrollViewer)->
  0654a4cc(Telerik.Windows.Controls.RadGridView)->
  065fcc8c(Telerik.Windows.Controls.GridView.GridViewHeaderRow)->
  0660ccf4(Telerik.Windows.Controls.GridView.DataCellsPresenter)->
  06629654(Telerik.Windows.Controls.GridView.ContainerTracking`1[[Telerik.Windows.Controls.GridView.GridViewCellBase, Telerik.Windows.Controls.GridView]])->
  06625a38(Telerik.Windows.Controls.GridView.ContainerTracking`1[[Telerik.Windows.Controls.GridView.GridViewCellBase, Telerik.Windows.Controls.GridView]])->
  06621dec(Telerik.Windows.Controls.GridView.ContainerTracking`1[[Telerik.Windows.Controls.GridView.GridViewCellBase, Telerik.Windows.Controls.GridView]])->
  0661f540(Telerik.Windows.Controls.GridView.ContainerTracking`1[[Telerik.Windows.Controls.GridView.GridViewCellBase, Telerik.Windows.Controls.GridView]])->
  06619520(Telerik.Windows.Controls.GridView.ContainerTracking`1[[Telerik.Windows.Controls.GridView.GridViewCellBase, Telerik.Windows.Controls.GridView]])->
  06617034(Telerik.Windows.Controls.GridView.ContainerTracking`1[[Telerik.Windows.Controls.GridView.GridViewCellBase, Telerik.Windows.Controls.GridView]])->
  06616e4c(Telerik.Windows.Controls.GridView.GridViewHeaderCell)->
  0655a4b4(Telerik.Windows.Controls.GridViewColumn)->
  0655a5a8(System.Collections.Generic.Dictionary`2[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]])->
  06600db8(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]][])->
  06519210(System.Windows.DataTemplate)->
  06517d98(SilverlightApplication1.Views.Page1)

I can send over the source of the solution as soon as you tell me how.  My company has an account with you but I'm not sure which account it is at this point so I can't open a support ticket.  I'll try to find out what that account is and submit a ticket but in the mean time is there any other way for me to get these files to you?  Its about 6 MB.
0
Milan
Telerik team
answered on 28 Jan 2011, 02:15 PM
Hello Dan,

it would be great if you can send us a sample application since we could not reproduce the leaks. I have converted the forum thread to a general feedback thread which is not publicly visible and you can freely attach the sample application (up to 20MB).

Thank you for your time. 


Kind regards,
Milan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Dan
Top achievements
Rank 1
answered on 28 Jan 2011, 03:14 PM
Thanks Milan...I actually submitted a support ticket after all but I'd be happy to submit the solution here as well but its still telling me that I can't upload .zip files.
0
Milan
Telerik team
answered on 28 Jan 2011, 03:23 PM
Hello Dan,

I am already looking at the support ticket. I will close this thread and report my findings in the support thread. Thank you for sending the sample. 


Regards,
Milan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Bilal Azam
Top achievements
Rank 1
answered on 03 Mar 2011, 06:49 PM
I am having the same issue. Did you guys find any solution or work-around?
0
Milan
Telerik team
answered on 09 Mar 2011, 08:00 AM

Hi Bilal Azam,

Could you please try our latest Internal Build which is available from our download section. If the issue is still there, I would like to ask you to send us a project demonstrating the faulty behavior. 



Regards,
Milan
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Dan
Top achievements
Rank 1
Answers by
Milan
Telerik team
Dan
Top achievements
Rank 1
Bilal Azam
Top achievements
Rank 1
Share this question
or