Solved

Memory usage

Posted on 2002-03-18
12
914 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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