Solved

Memory usage

Posted on 2002-03-18
12
908 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 68
Delphi and Access based Enumeration 9 59
Dev express lookupcombo 3 26
RESTRequest Parameter 4 30
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

10 Experts available now in Live!

Get 1:1 Help Now