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
1225
Searching for cells causes insane memory usage
posted

I am using 2009.1 w/the latest hotfixes.

I need loop through all my rows and find cells that match a value or a color.  At first I was doing ..

foreach (UltraGridRow aRow in gridConstraints.Rows)
{
 foreach(UltraGridCell aCell in aRow.Cells)
 {
  if(aCell.Appearance.BackColor == Color.Gray)
  {
   //do stuff
  }
 }
 
}

Each call to the the if statement cuased the memory to jump like crazy, after about 100 rows I am up to 1-1.5GB of memory usage.  So I thought maybe the Color.Gray was allocating some memory everytime so I thought I would try comparing a value.  The same problem happens...so I thought I would try this with LINQ like this..

foreach (UltraGridRow aRow in gridConstraints.Rows)
{

 List<UltraGridCell> cells = (from UltraGridCell c in aRow.Cells
  where c.Value == "X"
  select c).ToList();


 foreach (UltraGridCell aCell in cells)
 {
 }
 
 cells.Clear();
    cells = null;
}

...hoping the .Clear() and setting the list to null would clear the used RAM, but it is still using the same amount.

So my questions are why does doing a compare cause the memory to increase? How can I do this w/o the memory increasing or how can I release the used memory after each compare?

Parents
  • 469350
    Offline posted

    The grid creates the cell objects for a row lazily - that is... the UltraGridCell is not created unless someone tries to access it. Row objects are the same way.

    So by looping in this way, you are forcing the creation of an UltraGrid and UltraGridCell object for every row and cell in the grid. If you have a lot of rows/cells, then this can quickly add up to a lot of memory. Although, you must have quite a lot to reach 1.5GB.

    It's hard to give you any specific advice about how to achieve this more efficiently, since I don't really know what you are trying to do. But you should check out the WinGrid Performance Guide.

Reply Children