Re: How to release heap memory that is marked as 'free'
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 14 Apr 2006 23:11:15 -0400
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,Joseph M. Newcomer [MVP]
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
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
.
- Follow-Ups:
- Re: How to release heap memory that is marked as 'free'
- From: Michael Evenson
- Re: How to release heap memory that is marked as 'free'
- References:
- How to release heap memory that is marked as 'free'
- From: Michael Evenson
- Re: How to release heap memory that is marked as 'free'
- From: Ajay Kalra
- Re: How to release heap memory that is marked as 'free'
- From: Michael Evenson
- How to release heap memory that is marked as 'free'
- Prev by Date: Re: "Remembering" dialog size and position
- Next by Date: Re: How to release heap memory that is marked as 'free'
- Previous by thread: Re: How to release heap memory that is marked as 'free'
- Next by thread: Re: How to release heap memory that is marked as 'free'
- Index(es):
Relevant Pages
|
Loading