I am currently storing about a million rows into a DataTable,
this takes about 600 Mb RAM.
So, when you run the application it with store a 1 000 000 rows in a DataTable and display that on a GridView. When you close the Application this will obviously clear the memory.
I will Like to give the user this option, in other words when the user tries to close the form he will be asked whether he wants to clear memory or not.
The reason for doing this is that does not have to wait for the data to be read into the Datatable each time he runs the application.
…. I am fairly new to C#, so I apologize if this is an in appropriate question here.
You can only keep something in memory if there is a running application / process with that data in memory – if your application closes (and there is only 1 instance of your application open with that data in memory) then the memory will be released. If you want to keep it in memory then your only options would be
A much better idea would be change the way your application works with large data sets so that it doesn’t need to keep it all in memory, for example if you display all of that data in a large list view then use a virtual list view so that only those rows currently being displayed to the user are loaded into memory. You can then store your data either in an external database or a semi-permanent file (such as a SQLite database).
Or just load the data set each time like you currently are.