I'm having trouble cleaning up memory in a datagrid.
I have a datagrid that is set a datatable as its datasource every 5
seconds - each datatable assigned has the same structure but different
content.
When I perform the following line of code:
this.dbgEvents.SetDataBinding(e.Table, "");
the data on the datagrid is changed to reflect the new data.
The problem I am experiencing is that memory is not being cleaned up
properly. I'm getting the following objects hanging around:
System.WeakReference
System.Windows.Forms.BindingContext.HashKey
I've found these by using the .NET Memory Profiler application.
As the application loops and assigns a new datasource to the datagrid
these objects build up and consume memory.
I've tried the following to free the memory with no success:
if(dbgEvents.DataSource != null)
((DataTable)this.dbgEvents.DataSource).Dispose();
this.dbgEvents.SetDataBinding(e.Table, "");
Can anyone help with how to cleanup memory from a datagrid? It appears
as though the datagrid is still clinging to some objects and thus the
garbage collection cannot remove them.
Thanks,
Neo