Memory leaks with OpenFileDIalog, SaveFIleDialog, and DataGridView in WinForms
Hello!
I'm noticing memory leaks when doing the following:
* using
OpenFileDialog
or SaveFileDialog
, even inside using
* Adding new rows to a DataGridView (seems like clearing the table doesn't free anything?)
I've been researching for a few hours now and haven't come across any solutions yet. Does anyone know what could be going on? I've attached some code examples that should give more details.9 Replies
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
My application's memory usage would increase from 30 to 47mb, and wouldn't go back down once the dialog was closed. The memory usage would continue to increase every time the dialog is opened.
Also, adding a lot of rows to the DataGridView would have the same results
As for tools, I only used VS 2022's memory usage chart and task manager
The memory usage kept climbing and would not go back down, even when calling
GC.Collect
I mean, 47mb isn't a lot. The runtime will happily allocate that much if it needs to at some point, and it won't bother giving it back to the OS unless the OS asks for it
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Ah
I guess I misunderstood how that would work
Is there anything I can do to help mitigate excessive memory usage when loading lots of data into a table?
Also, why wouldn't the runtime give the memory back to the OS if it's done using it?
what if it wants to use it again
then you gave it back just to take it again
ah, right
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Yes