I am currently using a DataGridView control in my application, and I am facing this problem. I don't use DataBinding at all, just a manual population. The data that I put in them is not so much. Usually we talk about 20 rows of 20 columns of data.
The workflow for this control is that I have a ComboBox with different datasets that I load when you select them. Thus, the general use case moves cyclically through the data sets in the comboBox and sees their visualization in the dataGrid. What I see is that when people cycle through datasets, the memory usage of the application instantly goes from 100 MB to 1100 MB, and then drops down when the GC starts working. But if you quickly go through the datasets (i.e. faster than the GC's outputs), you will run out of memory and the application will die.
After debugging, I found that the reason MAIN, why the memory jumps up like crazy, is because I have several columns in this datagrid that are related to the image type. I use them to display a 16x16 icon that indicates the status for this line. These icons are stored in an ImageList, and I just set them as the value for this cell when I fill the rows of the data grid. If I take out the images and replace them with plain text, I absolutely do not see a burst of memory.
So what is the deal? Why are tiny 16x16 images making the control go crazy with my mind?
Additional Information:
My logic when switching datasets:
- Clear all grid lines: dataGrid.Rows.Clear ();
- Clear all columns: dataGrid.Columns.Clear ();
- Add columns to the dataGrid control: (most row types and some DataGridViewImageColumn)
- Add the data that I use line by line using dataGrid.Rows.Add (object [] data); (data includes images that I need to use as icons).
source share