Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

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

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
softbreeze
Asked:
softbreeze
  • 4
  • 4
1 Solution
 
MerijnBSr. Software EngineerCommented:
it says in the tags you are using Delphi 2007, is this true?
0
 
softbreezeAuthor Commented:
Yes: CodeGear" RAD Studio 2007  Version 11.0.2902.10471 with the December update and the April Hotfix
0
 
MerijnBSr. Software EngineerCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
softbreezeAuthor Commented:
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
 
MerijnBSr. Software EngineerCommented:
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
 
softbreezeAuthor Commented:
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
 
MerijnBSr. Software EngineerCommented:
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
 
softbreezeAuthor Commented:
Thanks for your time
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now