Re: How to release heap memory that is marked as 'free'



There is no such thing as garbage collection in C or C++. Only if you are using Managed
Code and using managed objects will you see any form of garbage collection. It sounds to
me like the allocator is working the way it is supposed to. The phenomenon you are seeing
is known as "memory fragmentation" and is one of the serious problems of storage
allocation. The solutions are all nontrivial. The memory is *not* part of the working
set unless it is being used. I'm not at all sure what you mean by the phrase "all other
processes running on the machine have to get their memory from the virtual memory pool".
By one interpretation, *ALL* memory is from the "virtual memory pool". The sentence,
however, just doesn't make any sense.

You are confused about memory and how it behaves. If a page isn't being used, it will
eventually be paged out, and there's nothing special you need to do to make this happen.
This is what the Virtual Memory Manager does, and there's no reason you need to do
anything about it. There is certainly no reason to force pages to go out. What makes you
think this is actually a problem? Perhaps you are looking at the process viewer or the
task manager? What makes you think those numbers have any meaning? (They are only vaguely
useful only some of the time under limited conditions). Of course, if you have a heap
walker that walks the heap, it touches all the pages which aren't otherwise being used, so
it has a profound negative impact on both your working set size and your overall
performance, by forcing pages that should otherwise be left on the disk to be paged back
in. So your attempt at measuring performance definitely makes the problem worse.

I'd say leave well enough alone, and don't do anything.
joe

On Thu, 13 Apr 2006 09:29:47 -0400, "Michael Evenson" <mevenson@xxxxxxxxxxxx> wrote:

Ajay,

Actually the memory does still belong to the process, but has been freed.
Apparently Windows does not reclaim the freed memory from the heap until it
is needed. This is all well and good except that , if Windows cannot find a
large enough contiguous block of memory upon a request for allocation, it
prefers to use virtual memory over doing a garbage collection to find more
memory. The freed memory becomes part of my process's 'working set'.
Eventually, my process consumes so much memory in it's working set (which
is marked as free since there is no leak) that all other process running on
the machine have to get their memory from the virtual memory pool.

I remember that there is a way to force Windows to reclaim the freed memory,
but it invovles something to do with forcing the process to swap to disk.
When this happens, all of the memory allocated to the process is garbage
collected and the freed memory is returned to Windows. I just canot remember
how to force the process to swap. I remember having to get the process ID of
the application and doing some system call to force it out of memory (I
think).

Mike




"Ajay Kalra" <ajaykalra@xxxxxxxxx> wrote in message
news:1144934421.595893.228090@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
it shows a VERY large amount of memory that is free but has not been
returned to
the operating system.

How do you figure this? That would mean that your process is still
using that memory.


---
Ajay


Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
.



Relevant Pages

  • Re: VIRTUAL MEMORY
    ... In task manager look at the performance tab and repost the PF Usage ... What virus was ... Hard to know if you dont know about computers I know. ... Are you using one of those memory managers which free up memory. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: GC Handle leaks....
    ... Note that you can use many features of SOS in VS 2005, ... to check the .Net memory and related GC counters and the GC Handles for the ... The handles in Task Manager relates to operating system handles, ... It means the GCHandle doesn't permit the object to be collected. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Watching memory use. What tools can I use
    ... > application rising second by second. ... > (I wish we were able to do garbage collection ourselves. ... Windows memory manager works, how and what kind memory gets allocated, this ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Physical Memory
    ... Thanks for your help, John. ... As for the services just use the Windows Services Management Console to ... Remote Access Connection Manager ... gig Pentium 4 processor and apparently a half gig of available memory, ...
    (microsoft.public.windowsxp.general)
  • Re: Scalable memory manager for Delphi.
    ... Performance should be equal or better than any other manager on the market. ... We found performance to be generally equal to MultiMM yet offers several ... memory corruption. ... Xeon testing with it, however, the latest demo app hasn't been run on Xeons ...
    (borland.public.delphi.thirdpartytools.general)

Loading