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
328 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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