title: .NET DataGridView control uses up a TON of memory for me
body: <p>I am using a DataGridView control in my app at the moment and I am hitting a weird memory issue with it. I am not using DataBinding at all, just manual population. The data that I am putting in there is not a lot at all. We're talking about 20 rows by 20 columns of data at the most usually. </p>
  
  <p>The work flow for that control is that I have a ComboBox with different "data sets" that I load as you pick them. So a common usage scenario is cycling through the data sets in the comboBox and seeing them render in the dataGrid. What I am seeing is that when people cycle through the data sets, the app memory usage jumps from 100MB to 1100MB instantly and then drops back down when GC kicks in. But if you cycle through the data sets quickly (i.e. faster than the GC kicks in), you will run out of memory and the app will die. </p>
  
  <p>After debugging, I found that the MAIN reason the memory jumps up like crazy is that I have some columns in that datagrid that are of Image Type. I use them to display a 16x16 icon that indicates status for that row. These icons are stored in an ImageList and I just set them as the value for that cell as I populate the rows of the data grid. If I take out the images and replace them with simple text, I see absolutely no memory spikes whatsoever. </p>
  
  <p>So what is the deal here? Why do images, tiny 16x16, cause the control to go crazy on my with memory like that? </p>
  
  <p>More info:</p>
  
  <p>My logic as you switch data sets is:</p>
  
  <ul>
  <li>Clear all the grid rows: dataGrid.Rows.Clear();</li>
  <li>Clear all the columns: dataGrid.Columns.Clear();</li>
  <li>Add the columns to the dataGrid control: (most type string, and some DataGridViewImageColumn)</li>
  <li>Add the data I have row by row using dataGrid.Rows.Add(object[] data); (the data includes the images I need to use as icons).</li>
  </ul>