Re: How to release heap memory that is marked as 'free'
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 14 Apr 2006 23:21:07 -0400
Wrong. What SetProcessWorkingSetSize does is screw up your process by forcing all the
pages out. It doesn't free anything; it just gives the illusion of freeing something, and
consequently it is actually a Really Bad Idea. I think it was Mark Russinovich who coined
the term "fraudware" for programs that do this.
Believing any of those numbers leads to erroneous solutions for non-problems. If you slow
down, it means you have badly fragmented memory, and "returning" memory to the OS is not
going to solve things. You need to rethink the entire problem that is causing the
fragmentation, not apply superficial non-solutions to the problem.
SetProcessWorkingSetSize is working as advertised; the problem is that it isn't even
vaguely related to solving your problem, and its use is inappropriate.
I've spent a nontrivial part of my career writing and optimizing storage allocators. You
need to understand why all this memory is being allocated. If you have a gigabyte image,
you are doing a lot of allocations. Whie a heapwalker is very informative, it cannot be
used in conjunction with any tools such as process viewer, manipuating the working set, or
any similar tools; it completely invalidates their information. So you need to understand
exactly where all that storage is going. It sounds to me like chronic fragmentation
syndrome. And that takes a lot of work to fix. The fix will not ever involve
SetProcessWorkingSetSize.
joe
On Thu, 13 Apr 2006 10:26:29 -0400, "Michael Evenson" <mevenson@xxxxxxxxxxxx> wrote:
Tom,Joseph M. Newcomer [MVP]
I have found that using the SetProcessWorkingSetSize function does
immediately show the memory being returned in task manager. I set a
breakpoint just before the call and the memory usage for the process is over
4MB. Immediately after the call, Task Manager shows the memory usage to be
around 130K which is what I would expect. When I then look at the heap dump,
I still have a very large amount of 'FREED' memory that belongs to my
process's allocated memory pool. Then when I go to allocate a very small
amount of memory (say for a local CString), the memory usage in Task Manager
shows application has the original 4MB of memory allocated. This 4MB value
eventually grows to over 1GB during program execution and it slows to a
crawl. By the way, I should mention that all of my calls to 'new' to
allocate memory that I have control over inside my application are done at
program startup and NOT within the loop where the memory seems to be getting
allocated and released.
I am thinking that the SetProcessWorkingSetSize function is not working
as advertised. Is this possible. I am checking the return code from
SetProcessWorkingSetSize and it is non-zero indicating that it was
successful.
Mike
"Tom Serface" <tserface@xxxxxxx> wrote in message
news:OF6$KOwXGHA.3868@xxxxxxxxxxxxxxxxxxxxxxx
Hi Michael,
I've seen the amount of memory for a process stay at a higher amount, but
once the memory is freed (especially globally allocated memory) Windows
seems to consume it again for other programs as needed. Are you seeing
other program "not" getting memory after you free it? Do the same
programs work OK if you exit your program first? Could it be that you've
allocated memory "around" the large block so the OS can't get it because
it's discontiguous? This article was interesting:
http://www.rsinc.com/services/techtip.asp?ttid=3346
Tom
"Michael Evenson" <mevenson@xxxxxxxxxxxx> wrote in message
news:5uGdnT3CS9jSz6PZRVn-vA@xxxxxxxxxxxxxxx
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.
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
- Re: How to release heap memory that is marked as 'free'
- From: Tom Serface
- 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: How to release heap memory that is marked as 'free'
- 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
|