I have an MDI which has a child form. The child form has a DataGridView in it. I load huge amount of data in the datagrid view. When I close the child form the disposing method is called in which I dispose the datagridview
this.dataGrid.Dispose();
this.dataGrid = null;
When I close the form the memory doesn't go down. I use the .NET memory profiler to track the memory usage. I see that the memory usage goes high when I initially load the data grid (as expected) and then becomes constant when the loading is complete.
When I close the form it still remains constant. However when I take a snapshot of the memory using the memory profiler, it goes down to what it was before loading the file. Taking memory snapshot causes it to forcefully run garbage collector.
What is going on? Is there a memory leak? Or do I need to run the garbage collector forcefully?
More information:
When I am closing the form I no longer need the information. That is why I am not holding a reference to the data.
Update
It is a requirement for me to load all the data at once. The memory usage goes really high when there is a lot of data so I am wondering if I am doing something wrong and the garbage collector is not being run but on the other hand when I look at the profiler it does show that when it takes a snapshot the memory usage decreases. So I am unable to understand what is going on.