Solved

Will the working set of an app shrink automatically if the memory causing it to grow is freed?

Posted on 2008-06-12
8
332 Views
Last Modified: 2010-04-21
I have an app that the working set keep growing during the life of the app. Initially I thought this might be a memory leak but none are detected using EurekaLog. The app allocates a chuck of memory for a data structure and places it on a list. The number of allocations vary from 1 to 1024. I allocate the objects, place them on the list, use them, and then free all of them. Thirty seconds later I do it again. This is the only memory allocations done in the app by me. Should I expect to see the working set size shrink after I free the memory? I'm using the following code snippet to get the working set size:

using psAPI....
 
function GetMemoryUsed: DWord;
var
  pmc:         PPROCESS_MEMORY_COUNTERS;
  cb:          Integer;
begin
     cb := SizeOf(_PROCESS_MEMORY_COUNTERS);
     GetMem(pmc, cb);
     pmc^.cb := cb;
     Result := 0;
     if GetProcessMemoryInfo(GetCurrentProcess(), pmc, cb) then
       begin
       Result := pmc^.WorkingSetSize;
       end;
     FreeMem(pmc);
end;

Open in new window

0
Comment
Question by:softbreeze
  • 4
  • 4
8 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 21772358
it says in the tags you are using Delphi 2007, is this true?
0
 
LVL 1

Author Comment

by:softbreeze
ID: 21773348
Yes: CodeGear" RAD Studio 2007  Version 11.0.2902.10471 with the December update and the April Hotfix
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 21776403
ok, in that case you (probably) won't have a problem with memory fragmentation.

How did you check for leaks with Eurekalog? If something leakes while the application is running, but this leaked memory _is_ cleaned up when you close your application, it's hard to detect with tools like Eurekalog.
0
Technology Partners: 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 1

Author Comment

by:softbreeze
ID: 21777441
It is my understanded that when you select the option to check for memory leaks it keeps track of all memory allocations and deallocations. When the program exits it reports the allocations that were not freed. I've only just started using it and it seems to be very reliable.
My original question though was 'Should I expect to see the working set size shrink after I free the memory?' I've done OS development on several well known operating systems and some shrink the working set back to the highest memory allocation for the address space others don't. I'm just not sure with the Windows.  
I've narrowed it down to a few calls to the Service Control Manager (SCM) to return all the services on various servers on my domain. I still searching the code...
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 21777703
I'm actually not sure, you can't depend on it. There is also the Delphi MM in between which might keep memory pre-allocated.
0
 
LVL 1

Author Comment

by:softbreeze
ID: 21779697
If you are not sure, how can you state that 'you can't depend on it'? It works one way or the other and it is not a crap shoot.

I believe based on a little testing that windows does reduce the working set as memory is released. I was looking for confirmation. I also believe that I have a design flaw that prior to releasing the memory I must allocate some that causes the working set to grow. The fact that the other memory was freed would not alter the 'new' larger working set size. I've been looking for days for such a possiblity in my code. So far I haven't found it.

Thanks anyway
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 250 total points
ID: 21781833
What I tried to say is that you don't have control over what the MM does with memory you release, it might as well keep it allocated, or free it later...
0
 
LVL 1

Author Closing Comment

by:softbreeze
ID: 31466665
Thanks for your time
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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