Solved

Memory usage

Posted on 2002-03-18
12
904 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now