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
334 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
[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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

734 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