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

Grid Refresh Causes a Memory Leak

2 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Menol
Top achievements
Rank 1
Menol asked on 17 Mar 2014, 10:27 AM
Hi, we have a fairly complicated system that is completely generated on the go.

The Grid is the main component and all columns, including template columns are created and populated on the fly.

I use ASP.NET Ajax package.

we have a mechanism that ignites an Ajax request every n seconds to refresh data in the grid.

We use a Telerik ajax panal for this. 

Whenever the ajax call is received, the Ajax panel recreates the grid from the scratch and then the NeedDataSource event handler (Simply set the datasource of the grid to  

PROBLEM : and the BROWSER memory keeps growing with each refresh until the browser crashes.

When I profiled the browser, I found that even though the browser fires GC it cannot recover memory. 

Browser memory keeps increasing with every refresh and this is proportional to the record count of the grid.

I THINK THE OLD DATA OF THE GRID IS NOT RELEASED WHEN THE GRID IS REFRESHED.

This is the NeedDataSource event handler code. PLEASE REMEMBER THAT I RE-CREATE THE GRID AT REFRESH

        protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            Telerik.Web.UI.RadGrid tmpPointerToUIGrid = sender as Telerik.Web.UI.RadGrid;

            // override default grid page size at the initial run. (the custom paging is not in effect at this stage) 
            if (ssession.DVM.CurrentRequestType != REQUEST_TYPE.DATA_REFRESH && e.RebindReason == GridRebindReason.InitialLoad)
            {
                tmpPointerToUIGrid.PageSize = SymphonySession.FindObject(HttpContext.Current.Session).InitialiseResponse.PageSize.Options.Find(op => op.IsDefault == 1).Value;
            }

            if (ssession.DVM.CurrentRequestType != REQUEST_TYPE.DATA_REFRESH && string.IsNullOrEmpty(tmpPointerToUIGrid.MasterTableView.FilterExpression) && this.Model.FilterCriteria != null && this.Model.FilterCriteria.Count > 0)
            { this.Model.FilterCriteria.Clear(); } // clear filters when no filter is selectered.

            ssession.Trace_addStamp("processing data for grid");
            tmpPointerToUIGrid.DataSource = this.Model.GetDataSource((e.RebindReason == GridRebindReason.InitialLoad) && ssession.DVM.CurrentRequestType != REQUEST_TYPE.DATA_REFRESH, tmpPointerToUIGrid.PageSize, tmpPointerToUIGrid.CurrentPageIndex + 1);

            tmpPointerToUIGrid.MasterTableView.VirtualItemCount = this.Model.GridTotalRowCount;
            ssession.Trace_addStamp("done: data processing");

            if (ssession.DVM.CurrentRequestType != REQUEST_TYPE.DATA_REFRESH)
            {
                this.Model.GridFilterExpression = this.RadGrid1.MasterTableView.FilterExpression;  // save for future refresh commands 
            }

        }

Please help...


2 Answers, 1 is accepted

Sort by
0
Menol
Top achievements
Rank 1
answered on 17 Mar 2014, 10:34 AM
THIS IS THE PAGE_INIT CODE

        protected override void OnInit(EventArgs e)
        {
            this.RadGrid1 = new RadGrid();
            this.RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
            this.RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound);
            this.RadGrid1.ItemCreated += new GridItemEventHandler(RadGrid1_ItemCreated);
            this.RadGrid1.PreRender += new EventHandler(RadGrid1_PreRender);

            this.RadGrid1.AutoGenerateColumns = false;
            this.RadGrid1.ClientSettings.Resizing.ClipCellContentOnResize = true;
            this.InitGrid();
            this.RadGrid1.Skin = "Transparent";
            //this.RadGrid1.GridLines = GridLines.Vertical;
            //this.RadGrid1.EnableEmbeddedSkins = false;

            this.RadGrid1.AllowSorting = true;
            this.RadGrid1.CssClass = "CustomGridHeaderStyle";

            this.RadGrid1.MasterTableView.TableLayout = GridTableLayout.Fixed;
            this.RadGrid1.MasterTableView.HeaderStyle.CssClass = "CustomGridHeaderStyle";
            
            this.RadGrid1.AllowFilteringByColumn = true;
            this.RadGrid1.GroupingSettings.CaseSensitive = false;

            this.RadGrid1.SortCommand += new GridSortCommandEventHandler(RadGrid1_SortCommand);
            this.RadGrid1.SortingSettings.EnableSkinSortStyles = false; 
            this.RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);

            this.RadGrid1.ClientSettings.EnableRowHoverStyle = true;
            this.RadGrid1.ClientSettings.Scrolling.AllowScroll = true;
            this.RadGrid1.ClientSettings.Scrolling.UseStaticHeaders = true;
            this.RadGrid1.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(10);
            this.RadGrid1.ClientSettings.Selecting.AllowRowSelect = true;
            this.RadGrid1.AllowMultiRowSelection = true;
            //this.RadGrid1.ClientSettings.Resizing.ClipCellContentOnResize = true;

            this.RadGrid1.ClientSettings.ClientEvents.OnGridCreated = "GridCreated";
            this.RadGrid1.ClientSettings.ClientEvents.OnGridDestroying = "GridDestroyed";
            this.RadGrid1.ClientSettings.ClientEvents.OnRowClick = "RowClicked";
            this.RadGrid1.ClientSettings.ClientEvents.OnRowSelected = "RowSelectionChanged";
            this.RadGrid1.ClientSettings.ClientEvents.OnRowDeselected = "RowSelectionChanged";


            // cell context menu related settings
            this.RadGrid1.ClientSettings.ClientEvents.OnCellSelected = "CellSelected";
            this.RadGrid1.ClientSettings.ClientEvents.OnRowContextMenu = "RowRightClick";
            this.RadGrid1.ClientSettings.Selecting.CellSelectionMode = GridCellSelectionMode.SingleCell;
            this.RadGrid1.EnableLinqExpressions = false;  // this setting goes around a Telerik problem that's unknown as of the moment this code was written [http://www.telerik.com/community/forums/aspnet-ajax/grid/filter-rows-programmatically.aspx].

            this.RadGrid1.MasterTableView.AllowPaging = true;
            this.RadGrid1.MasterTableView.AllowCustomPaging = true;

            this.RadGrid1.MasterTableView.PagerStyle.AlwaysVisible = true;
            this.RadGrid1.MasterTableView.AllowMultiColumnSorting = true;

            this.gridPH.Controls.Add(RadGrid1);

            var scriptman = ScriptManager.GetCurrent(Page);
            if (scriptman != null)
            {
                scriptman.RegisterPostBackControl(ExportToCSV);
            }

            this.RadGrid1.ClientSettings.Resizing.AllowColumnResize = true;
            this.RadGrid1.ClientSettings.Resizing.AllowResizeToFit = true;
            this.RadGrid1.ClientSettings.Resizing.EnableRealTimeResize = true;

            this.RadGrid1.ItemStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("0xF0F0F0");
            this.RadGrid1.AlternatingItemStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("0xE8E8E8");
            this.RadGrid1.AlternatingItemStyle.BorderStyle = BorderStyle.Inset;
        }
0
Pavlina
Telerik team
answered on 20 Mar 2014, 09:52 AM
Hello Menol,

Please note that increasing the memory of your browser does not mean that there is memory leaks. We are using tools like sIEve for tracking down memory leaks in our controls and if we find any, we are doing our best to fix them as soon as possible.

Therefore, I would suggest to upgrade to the latest version of the controls (if you haven't already) and to test your application with sIEve or a similar tool. If they indicate memory leaks caused by our products, please send us a sample project via support ticket along with detailed reproduction steps and we will check it right away.

Regards,
Pavlina
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
Grid
Asked by
Menol
Top achievements
Rank 1
Answers by
Menol
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or