C1 Community
ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

[Silverlight.Datagrid] Memory Leaks

rated by 0 users
This post has 1 Reply | 1 Follower

Not Ranked
Posts 1
psflight Posted: Mon, Jun 22 2009 8:01 AM

Hi,
I'm using your Silverlight DataGrid in one of my projects and I'm experiencing some strange behavior when reloading the grid with new data or when sorting it. Memory increases like 2MB each time.

I'm using a datatable for binding the source and celltemplate for each column. I have inherited from TextBlock and used my own Class ("MyTextBlock") for binding the context. Basically what I do on the loaded event of the "MyTextBlock" is get from the DataContext the Row and bind the "MyTextBlock.Text" to the value of the row I Desire.

 i.e.:
 if (((C1.Silverlight.Data.DataRow)this.DataContext)[this.Tag.ToString()] != null)
 {
   context = ((C1.Silverlight.Data.DataRow)this.DataContext)[this.Tag.ToString()].ToString();
   t.Text = context;
 }

 I'm managing the SortChanged myself due to the BindingSouce is a DataTable whose colums type are String and we have some columns that should be decimal, so we needed to sort them as decimal.

 Here is the code of the Sort:

      public void DataGridExtended_SortChanged(object sender, C1.Silverlight.PropertyChangedEventArgs<C1.Silverlight.DataGrid.DataGridSortState> e)
        {
            if (e.NewValue.Direction != C1.Silverlight.DataGrid.DataGridSortDirection.None)
            {
                List<DataRow> rows = ((IEnumerable<DataRow>)this.ItemsSource).ToList<DataRow>();
                if (rows.Count > 0)
                {
                    IOrderedEnumerable<DataRow> enumerableRows = null;
                    C1.Silverlight.DataGrid.DataGridColumn col = (C1.Silverlight.DataGrid.DataGridColumn)sender;
                    bool isDecimal = false;
                    bool isDateTime = false;
                   
                    decimal valueDecimal;
                    string text = rows[0][col.SortMemberPath].ToString().Split(new string[] { "{_0_}" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("$ ", "");
                    isDecimal = (Decimal.TryParse(text, System.Globalization.NumberStyles.Any, null, out valueDecimal));

                    if (!isDecimal)
                    {
                        DateTime valueDateTime;
                        isDateTime = DateTime.TryParse(text, out valueDateTime);
                    }

                    if (e.NewValue.Direction == C1.Silverlight.DataGrid.DataGridSortDirection.Ascending)
                    {
                        if (isDecimal)
                        {
                            enumerableRows = rows.OrderBy(DataRow => decimal.Parse(DataRow[col.SortMemberPath].ToString().Split(new string[] { "{_0_}" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("$ ", "")));
                        }
                        else if (isDateTime)
                        {
                            enumerableRows = rows.OrderBy(DataRow => DateTime.Parse(DataRow[col.SortMemberPath].ToString().Split(new string[] { "{_0_}" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("$ ", "")));
                        }
                        else
                        {
                            enumerableRows = rows.OrderBy(DataRow => DataRow[col.SortMemberPath]);
                        }
                    }
                    else
                    {
                        if (isDecimal)
                        {
                            enumerableRows = rows.OrderByDescending(DataRow => decimal.Parse(DataRow[col.SortMemberPath].ToString().Split(new string[] { "{_0_}" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("$ ", "")));
                        }
                        else if (isDateTime)
                        {
                            enumerableRows = rows.OrderByDescending(DataRow => DateTime.Parse(DataRow[col.SortMemberPath].ToString().Split(new string[] { "{_0_}" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("$ ", "")));
                        }
                        else
                        {
                            enumerableRows = rows.OrderByDescending(DataRow => DataRow[col.SortMemberPath]);
                        }
                    }                   
                   
                    this.ItemsSource = enumerableRows;                   
                    rows = null;                   
                    enumerableRows = null;
                   
                }               
            }           
        }

 

Any help on this will be really appreciated, memory increases a lot crashing the browser.

Thanks

Top 10 Contributor
Posts 1,271
C1_LeoV replied on Fri, Jul 24 2009 5:48 PM

It's an unanswered old post.

Just in case, memory leaks were fixed in v1/2009 (May).
You can download the latest version from http://www.componentone.com/superproducts/studiosilverlight/

BTW, take into account that until the Garbage Collection is called, the memory "usage" will increase. it should go back to the real usage after it's called.

Regards and sorry for the delay in the answer, we missplaced the thread.

Follow me: Twitter.com/leovernazza/

Page 1 of 1 (2 items) | RSS
Contact ComponentOne: 1.800.858.2739 ©1987-2010 ComponentOne LLC All Rights Reserved.