Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
How to reduce memory usage when setting Cell Appearance?
posted

Hi,

I need to set the appearance (backcolour, forecolour, fontdata.name) of a large number of cells in a grid (over 100,000), and wonder which approach is recommended to a) reduce memory usage and b) achieve reasonable performance.

Initially, I was using code like the following:

cell.Appearance.ForeColor = colorBilledAndPaid; 

and I noticed that the heap contained 130 thousand Infragistics.Win.Appearance objects (as reported by windbg) -- approximately 1 per cell whose Appearance was being changed.  I noticed another post on this forum suggesting that, to improve performance,  cell Appearances should be set using predefined Appearance objects, so I changed to using code like the following:

// during form startup:

            paidCellAppearance = (Infragistics.Win.Appearance)cellAppearance.Clone();
            paidCellAppearance.ForeColor = colorPaid;
            paidCellAppearance.FontData.Bold = DefaultableBoolean.True;

// later, when painting the cells:

            cell.Appearance = paidCellAppearance;

Unfortunately, this approach used even more memory, and when I checked the heap using windbg there were now over 100,000 UltraGridCell objects (but the Infragistics.Win.Appearance had been reduced to a few dozen, as expected).

Is it normal that setting the Appearance of a cell would cause a new object to be created in memory (one per cell)?  If so, is there a different approach that is recommended when setting these colour and font properties for a large number of cells?  

If the per-cell memory usage isn't normal, then do you have any suggestions on what I might be doing to cause these UltraGridCell objects to be created on the heap?  The code that I'm using to access the cells involves hundreds of lines across 10 methods so I won't paste it all here, but the important parts are:

                foreach (UltraGridRow row in gridBuyLines.Rows.GetAllNonGroupByRows())
                {

                    // paint the child band
                   UltraGridRow airing = row.GetChild(ChildRow.First);
                   while (airing != null)
                   {
                      paintRow(airing);
                      airing = airing.GetSibling(SiblingRow.Next);
                   }
                   // paint the parent row
                   paintRow(row);
               }

... 

 private void paintRow(UltraGridRow row)
 {

                for (int intWeekNumber = 0; intWeekNumber < IntNumWeeks; intWeekNumber++)
                {
                    string strColumnName = "IntAiringsWeek" + (intWeekNumber + 1);
                    row.Cells[strColumnName].Appearance =  paidCellAppearance;
                    // actually,various if statements are used to determine which Appearance object to use here -- it isn't always paidCellAppearance, and not every cell has its Appearance set, but over 100,000 cells do
                 }

Sorry if this problem description is somewhat lame.  If the 2nd approach that I used is the right one but I need to set the .Appearance property more sparingly, then I'm OK with that.  (Until now, I hadn't realized that setting Appearance at the cell level was going to be a performance problem). But I just wanted to make sure that I wasn't barking up the wrong tree before restructuring the code.

Thanks,


Dan.