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



Tom,

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.





.



Relevant Pages

  • Re: How to take in a string of any size?
    ... >the contents into the allocated memory. ... nobody said the string started at the beginning of the file. ... >number of calls to realloc() isn't going to be excessive). ...
    (comp.lang.c)
  • Re: Interprocess Communication & Performance
    ... For instance if the data items are small and ... memory the performance hit from the synchronization will overwhelm things. ... to map the allocated memory in both processes. ... memcpy's then using shared file mapping I think. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: will I get Memory leak..
    ... dynamically assigned memory area will i get memory leak.. ... The problem with your code, on the other hand, is that your call to strcpywrites a null character to fp, which is one position past the end of the allocated memory. ... As a result of that error, the behavior of your entire program is undefined, which means that anything could go wrong A memory leak is very definitely a possibility from making that kind of mistake, but most of the other possible consequences of that mistake are much worse than memory leaks. ...
    (comp.lang.c)
  • Re: Memory leak when internal pointer passed out as parameter
    ... new block of memory when foo1 returns. ... within foo1 will remain in the system heap forever. ... The allocated memory will be returned to the system heap when the ... free the memory when the program exits, ...
    (comp.lang.c)
  • Re: show disassembly
    ... C++ defines three types of storage: ... The memory they occupy ... int* pOut = NULL; ... // Free allocated memory elsewhere. ...
    (microsoft.public.vc.language)