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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



HeapCompact is almost certainly not related to this problem, because it works on OS heaps.
The C runtime heap is not directly related to the OS heaps, which you can see if you read
the source code. The C runtime heap is essentially a single heap allocation of the
default heap. Study the sbheap.c code in the C runtime source. It shows how allocation
is really done for the C runtime heap, and it is clear from the code that the C runtime
malloc is used to subdivide a single HeapAlloc. HeapCompact will only deallocate heap
pages that are part of the HeapAlloc mechanism, and the C runtime is imposed on top of the
HeapAlloc mechanism.

There may be deep problems here, but thus far all the proposed solutions are somewhere
between erroneous and irrelevant.
joe


On Fri, 14 Apr 2006 08:38:04 -0700, "Alexander Grigoriev" <alegr@xxxxxxxxxxxxx> wrote:

If you really want to release committed but not allocated to the heap
memory, use HeapCompact. It will do what you actually need.

"Michael Evenson" <mevenson@xxxxxxxxxxxx> wrote in message
news:9aidncmnlJ_5IqLZRVn-jQ@xxxxxxxxxxxxxxx
Bo,

Reducing the amount of physical memory is what I am trying to do. I
want Windows to reclaim the freed blocks of memory that belong to the
process's working set. The documentation for SetProcessWorkingSetSize
states that the process will be swapped to disk if the last two parameters
are both -1, and the memory that has been freed will be removed from the
working set (physical memory) so that other processes can make use of it.
I am interpreting this to be a 'poor mans' garbage collector. Apparently
it does not work as advertised.

Does anyone know of any way to implement this with the SDK? I don't
want want to have to replace the memory management code that comes with
the C runtime. I don't understand why, if the memory has been freed that
Windows will not reclaim it.

Mike


"Bo Persson" <bop@xxxxxx> wrote in message
news:4a9gd1Frei4uU1@xxxxxxxxxxxxxxxxx

"Michael Evenson" <mevenson@xxxxxxxxxxxx> skrev i meddelandet
news:qMSdnUWen67B66PZnZ2dnUVZ_vSdnZ2d@xxxxxxxxxxxxxxx
Alexander,

Please elaborate.

Think of the difference between physical and virtual memory.

Reducing the working set size, minimizes the use of physical memory.
Temporarily.


Bo Persson



Mike



"Alexander Grigoriev" <alegr@xxxxxxxxxxxxx> wrote in message
news:OonG0swXGHA.456@xxxxxxxxxxxxxxxxxxxxxxx
You confuse your working set size and committed memory size.

"Michael Evenson" <mevenson@xxxxxxxxxxxx> wrote in message
news:gPWdnZgSioNDyaPZRVn-tQ@xxxxxxxxxxxxxxx
Never mind - I found it. I've been looking for this line of code for
days.

SetProcessWorkingSetSize (GetCurrentProcess (), -1, -1);

Calling this function is suppose to clear all freed memory from the
process's heap.

Mike


"Michael Evenson" <mevenson@xxxxxxxxxxxx> wrote in message
news:wKqdnSIT_cLY06PZRVn-uQ@xxxxxxxxxxxxxxx
I have added a heapwalker to my application to see what's happening
with the memory being consumed. After the app has run for a while, it
shows a VERY large amount of memory that is free but has not been
returned to the operating system. My application is written using
unmanaged C++ with Visual Studio .NET 2003. I have check for memory
leaks and there do not appear to be any. All of the places where I use
new to allocate memory have a corresponding delete for them.

I remember that I had this problem in another application a while
back, but I cannot remember exactly what I did to resolve it. It had
something to do with causing the process to flush the heap somehow
and I believe it involved forcing a swap on a periodic basis.

My question is: Does anyone know how to force Windows to reclaim my
process's freed memory.

Mike.












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: how to enlarger Java heap size?
    ... Is there a way to tell Java on the command line to take as much heap ... size as the physical memory or the virtual memory of the computer ... You could write a helper application that detects the installed physical memory and then passes that along as it starts the Java process. ...
    (comp.lang.java.programmer)
  • Re: Lcc-win32 extensions to C
    ... compiled with a C++ compiler or a C compiler. ... Yes, but if you do not use GC, you allocate more memory than needed to ... Using a non-GC'ed heap+ a GC'ed heap requires also more memory... ... Collector, since GC technologies are much more advanced than simple ...
    (comp.std.c)
  • Re: "Physical" memory bounds
    ... This gets tedious with discontiguous memory but I don't see ... is placed in the System Heap. ... Out of this, each task's stack is ... The dynamic memory allocator base allocator will use this label as the ...
    (comp.arch.embedded)
  • Re: IBM JVM and OS heap
    ... It was feeling that it's by design that memory was not released, ... shrinking the heap and releasing memory to OS are two different things. ... Whether any physical memory is released depends on the ability of the native ... decommitted on a heap shrinkage. ...
    (comp.lang.java.machine)
  • Re: Huge pages and small pages. . .
    ... you need to have them cached in the TLB; if the TLB runs out of ... >>> low end of the heap, until someone figures out a way to tell the system ... >> causing them to be COW'd to real memory. ... I believe the swapper will kill them fast once you have ...
    (Linux-Kernel)