Hi,
during testing yesterday I got an OutOfMemoryException when trying to load about 20.000 rows into UltraGrid. Today I was investigating little bit more why this exception occurs, detected a rather interesting thing:
In the UltraGrid I'm using one column to display the status of the data that is displayed in the row using different images in .png-format. Each of this images has a size of around 1k. I now loaded 10.000 rows of data into the UltraGrid both with displaying the status image and without showing it, examined the memory usage of my application with Windows Task Manager:
I can imagine, that UltraGrid needs some overhead to display the image but that it suddenly needs more than double of memory is imho a little bit to much. The way I'm initializing the image is in the InitializeRow event handler of the UltraGrid by applying following code snippet:
private void OnInitializeRow(object sender, InitializeRowEventArgs e) { UltraGridCell statusCell= e.Row.Cells["StatusRow"]; statusCell.Appearance.ImageBackground = Resources.StatusImage1; }
private void OnInitializeRow(object sender, InitializeRowEventArgs e)
{
UltraGridCell statusCell= e.Row.Cells["StatusRow"];
statusCell.Appearance.ImageBackground = Resources.StatusImage1;
}
StatusImage1 is the .png-file.
Is there maybe a better and less memory consuming way to do that?
Regards,
Wolfgang
Hi Wolfgang,
qbupoew said:Is there maybe a better and less memory consuming way to do that?
Absolutely. The way you are doing it here is terribly inefficient because you are forcing the grid to create an Appearance object for every cell.
Check out the WinGrid Performance Guide and take a look at the last section entitled "Re-use Appearances".
Hi Mike,
thanks for your instant reply, I did the changes in my implementation following your suggestions and it works like a charm. I tried it now with 50.000 rows and the memory consumption is around 233MB.
Thanks also for your valuable summary which I will read in details afterwards since there are surely more things to improve.
Regards Wolfgang