0

I have used pageheap for debugging heap corruptions in last four years. generally, I don't have any problems with it. But now I have faced with weird behavior. After enabling pageheap for my process in win7-sp1-x86 host using global flags with following flags: -Enable heap tail checking -Enable heap free checking -Enable Page Heap

I noticed crashes with out-of-memory exceptions. !address -summary command said that ~90% of virtual memory was consumed by PageHeap.

It is really strange for me, because, as I know, pageheap should not lead to such big amount of memory overhead.

Can please someone explain whats is the reason of such behavior?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Anz
  • 21
  • 3
  • 3
    pageheap tail checking 'adds' a protected page right at the end of each allocated block. A page normally is 4K, which is the reason you see the memory increase. Even smallest blocks get allocated at the end of the page, wasting around 8K in total. This increases memory usage from 30M to 400M for one of the apps I'm writing, for example. I'm allocating a lot of small blocks and optimizing this is not yet on the horizon. – ActiveTrayPrntrTagDataStrDrvr Nov 07 '12 at 09:15
  • 3
    is it possible that your application has a memory leak? Pageheap magnifies the effect of a memory leak. – Raymond Chen Nov 07 '12 at 09:23
  • 1
    !heap -s will show how many blocks, and as mentioned above, even the smallest block require 8K so out-of-memory is usually not a surprise – Kjell Gunnar Nov 07 '12 at 11:03

1 Answers1

0

When running an application with full page-heap enabled, 2 pages (4kb) are allocated for each 'malloc'. When the memory is freed, these pages (or may be only the first one) are still 'reserved' : they don't occupy any physical or page file memory, but the virtual address range is made unavailable and an access violation is raised when trying to access this memory. This allows to catch read-after-free kind of bugs. Thus, the virtual address space of the application keeps on increasing even if you properly call free for each malloc.

Thierry Franzetti
  • 1,763
  • 12
  • 12