Solved

Memory usage

Posted on 2002-03-18
12
911 Views
Last Modified: 2007-11-27
Hi

Can anybody explain this.

I have a crappy delphi app. which uses around 12 MB.
When I minimize it, it drops to use about one MB, that I understand fine. But when I maximize it again it only uses 3 MB. What has happend ? is there a 9MB memory leak which Windows have cleaned up for me ?
0
Comment
Question by:bnz
12 Comments
 
LVL 3

Expert Comment

by:raidos
ID: 6876864
No, When you minimize the App Windows decides to put most data of that process into the Swap, and when you Restore it Windows doesn't crunch up all the data, until it is actually needed...

Regards
//raidos
0
 
LVL 17

Expert Comment

by:geobul
ID: 6877161
Hi,
What's the memory usage immediately after starting that app?

Possible situation: Your app creates objects and allocates memory for them. After some time the app frees some objects correctly but Windows memory manager doesn't deallocate freed memory at that time. Minimizing/restoring forces that process.

Regards, Geo
0
 

Author Comment

by:bnz
ID: 6877195
Is there anything I can do to trim the memory usage

I tried to call
SetProcessWorkingSetSize( HInstance, $FFFFFFFF, $FFFFFFFF );

Read about it a delphi usergroup, but it didn't do the trick
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 3

Expert Comment

by:SteveWaite
ID: 6878878
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6879153
>> SetProcessWorkingSetSize( HInstance, $FFFFFFFF, $FFFFFFFF );

Uah!!! Terrible!!! You've read THAT on a Delphi usergroup?

It has to look like this:

SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF );

HInstance is not a process handle, it is the module handle of the executable module, which is a *totally* different thing...

Regards, Madshi.
0
 

Author Comment

by:bnz
ID: 6879234
I tried another thing. I created a new application with a button, it uses 1.7MB I call SetProcessWorkingSetSize (the correct way) and it drops to around 0.7MB and stays there no matter what I do. Why do Delphi reserve 1.7MB when 0.7MB seems to be enough.

Madshi:
hehe ehmm not quite, I read about SetProcessWorkingSetSize and filled hInstance in ...my self :)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6879325
Don't know what Delphi does there and why. Does SetProcessWorkingSetSize solve the problem with your original application, too?
0
 

Author Comment

by:bnz
ID: 6879327
Yes it seems so
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6879342
Fine! Please don't ask me to explain it - I can't...   :-/
0
 

Author Comment

by:bnz
ID: 6879433
hehe, so your knowledge isn't inexhaustible after all ;)
I almost thought so
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6879449
:-)
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 100 total points
ID: 6896606
Delphi is just allocating 1 MB of memory for it's internal heap, I guess. This heap is used every time you create a new object. Since it's in RAM the creation of objects is pretty fast.
Once you call SetProcessWorkingSetSize this allocated memory is send to the swapfile and as long as you don't create new objects or use getmem-related commands to allocate more memory the reserved memory that's on the swap-file isn't required. But once you start allocating memory again, Delphi has to get the reserved memory from the swapfile which is a bit slower than allocating it directly.
Don't forget, within Windows memory manager Delphi uses it's own memory manager to allocate big chunks of data and to divide it in very small parts.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question