How to free memory with OpenFileDialog?

Winform OpenFileDialog, every time I open it, the memory increases, dispose () and OpenFileDialog = null do not work, the memory does not lose ..

how to fix it?

private void btnLocalPicture_Click(object sender, EventArgs e) { OpenFileDialog ofdSelectPicture = new OpenFileDialog(); ofdSelectPicture.Filter = "PicFile|*.jpg;*.png;*.jpeg;*.gif;*.bmp;*.tif"; if (ofdSelectPicture.ShowDialog() == DialogResult.OK) { if (showPicture != null) showPicture.Dispose(); showPicture = Image.FromFile(ofdSelectPicture.FileName); if (pbShowPicture.Image != null) pbShowPicture.Image.Dispose(); pbShowPicture.Image = showPicture; path = ofdSelectPicture.FileName; WordTip.Visible = false; if (pbShowPicture.Image != null) picOK.Enabled = true; } ofdSelectPicture.Dispose(); //not working ofdSelectPicture = null; //not working GC.Collect(); } 
+4
source share
1 answer

You can see what happens with the tab "Project + Properties", "Debug", check the option "Enable unmanaged debugging". Run the program and select the output window. Display the dialog.

Now you will see a list of loaded DLL files in your process. These are shell extensions registered on your computer. What you get is unpredictable, everyone has their own set of favorite extensions. Programmers, as a rule, have a lot of them.

Yes, this extension will consume memory in your process. Just because these DLLs take up space in your virtual memory address space. But also because these DLLs allocate memory for their own use. And poorly written, of course, can comfort the memory. Remember that the memory allocated by these extensions is always unmanaged memory, so make sure you have a good tool that shows you a leak. Something like TaskMgr.exe is not enough.

Two main things you can do. First, itโ€™s easy to ignore, this problem is specific to your machine, and your user will not have the same problem. You cannot fix the leak, you do not have the source code for the extension. Or you can pursue the intruder using the AutoRuns SysInternals utility. It shows you which shell extensions are registered and allows you to register them by clicking the check box.

+7
source

All Articles