Why is it that when I start up my Delphi application, the memory usage is,
say, 4,000k.
But when I minimize it, it becomes 400k
When I restore it again, it becomes 1000k, and stays around 1000k. Why did
it suddenly shrink??
So then I tried this trick:
Before my application is run (application.run), I minimize and restore it by
code (application.minimize.. application.restore). And voila, the mem usage
becomes 1000k on startup.
Of course, I want the mem usage on my app to be as small as possible. But
what's the deal with this? What's going on here?..
That's not related to Delphi it's a Windows thing (you should notice it with
other apps). There is an API call you can make to do the memory thing for
you without resorting to minimizing. But I can't remember what it is.
Cheers,
Anthony Richardson
Viewpoint (SA) Pty Ltd
It must be one of the secret API's that MS work tell us about...
if (!IsMSApp())
UseLotsaMemory();
" The effect you are seeing is something that
the OS (at least NT & W2k) is doing when any app is minimized. It is paging
the app out of memory. When you restore it, it gets paged back in, but the
extra memory used in the initialisation etc. is no longer required and hence
the reduction in size." Mark Grimmond.
" Make an API call to SetProcessWorkingSetSize (with values of -1 and -1)
when
the app is minimized. The effect of making the call is that memory reserved
by the app (but not necessarily in use) is returned to the OS." Dave
Nottage.
Oops bad cut'n'paste, this is a clearer version.
"Make an API call to SetProcessWorkingSetSize (with values of -1 and -1).
> "Make an API call to SetProcessWorkingSetSize (with values of -1 and
> -1). The effect of making the call is that memory reserved by the app
> (but not necessarily in use) is returned to the OS." Dave Nottage.
Thanks Anthony.
But is this something we should even be worried about, or bothering with?
>
> But is this something we should even be worried about, or bothering with?
No. Windows will automatically reclaim memory when it needs it. The
numbers displayed in Task Manager have little direct relationship to the
actual memory hit of the application as it relates to memory required by
other apps. Look at Process->Private Bytes in NT/2000 Performance
Monitor to get a better idea.
HTH,
-Craig
--
Craig Stuntz (TeamB) · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase WebLog: http://delphi.weblogs.com
InterBase PLANalyzer (Free IB optimization tool):
http://delphi.weblogs.com/IBPLANalyzer
> But is this something we should even be worried about, or bothering with?
No, not really.
--
Rudy Velthuis (TeamB)
"There is no idea so simple and powerful that you can't get zillions
of people to misunderstand it." -- Alan Kay
Just for fun, try this same trick with the Delphi IDE. Mine was at 85 Megs
(after doing a build all with a large project group). After a minimize it
went to less than 7 Megs. As others have pointed out it's just windows
swapping memory out when the app gets minimized (the idea is you're probably
not using the app at that point). Once you bring it back and start actually
using it the memory will start going back up. Someone once wrote a Delphi
expert to call the API automatically. I'm not sure how much good that
really does for you.
-Mike
>It must be one of the secret API's that MS work tell us about...
>
>if (!IsMSApp())
> UseLotsaMemory();
You forgot to add CrashRandomly();