Re: Resource Leak
"jc" <jc@discussions.microsoft.com> wrote in message
news:78AE1A30-9259-4C79-A329-AA8749266852@microsoft.com...
I noticed (using Task Manager), that once the dialog box
opens, the application memory usage increases from
3 MB to 30 MB, but when the dialog box is closed, the
memory usage does not decrease. Since, the dialog box
variable is declared locally, shouldn't the memory decrease,
because the dialog box variable is no longer in scope?
Is the application leaking?
Not necessarily. The Open File dialog is a Windows system dialog whose
resources and code are in a Windows DLL. When you first show it, Windows
loads this DLL and instantiates the dialog. But when the dialog is closed,
Windows might not be aggressive about unmapping the DLL from your process,
or even reclaiming the instance memory of the dialog (it might just mark it
as unused and available for a subsequent allocation).
To make Windows aggressively reclaim as much memory as possible, call
SetProcessWorkingSetSize((SIZE_T) ???1, (SIZE_T) ???1) as stated in
http://msdn.microsoft.com/en-us/library/ms686234%28VS.85%29.aspx
I believe this is called for you if you minimize your window, so if you
minimize the dialog, you can achieve the same thing without adding any code.
-- David