Solved

Memory usage

Posted on 2002-03-18
12
905 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection between libmysql.dll and MySQL Versions 7 87
Delphi: Connect to running MS Outlook 4 47
JAudiorecorder record freezing the app 29 59
Base1 Encode/Decode 3 67
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 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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

20 Experts available now in Live!

Get 1:1 Help Now