I had similar thoughts. This is flying in the dark a bit as I've no real idea if the CRT malloc uses the process heap or another heap or heaps. I tried using the following apis to try and compact the heap after the AoH is undef'd:

use Win32::API::Prototype; ApiLink( 'Kernel32', q[ HANDLE GetProcessHeap(void) ] ) or die $^E; ApiLink( 'kernel32', q[ DWORD HeapCompact( HANDLE hHeap, DWORD dwFlags + ) ] ) or die $^E; my @idsMap; my @AoH; my $cnt = 1; $|++; for my $i ( 1 .. 40 ) { my $start = "aaa"; my %hash; keys %hash = 250_000; printf "\r$i\t"; for my $j ( 1 .. 250000 ) { $hash{ "$cnt $i $j $start" } = $cnt; $cnt++; $start++; } $AoH[$i] = \%hash; } print "Total size: ", total_size( \@AoH ); undef @AoH; print "did undef of array\n"; <>; print HeapCompact( GetProcessHeap( 0 ), 0 ) or die $^E; ...

It does something, and takes quite a while doing it, but the result is that the largest contiguous chunk after compaction (of the process heap) is a little over 1MB which isn't enough to make any difference.

Looking at the process memory map, there appear to be multiple heaps, but I haven't worked out a way of determining which is the process heap.

One possibility is to enumerate all the heaps and run HeapCompact() on them all. Besides being slow, I'm not sure that it would achieve very much?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^4: out of memory problem after undef by BrowserUk
in thread out of memory problem after undef by sduser81

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.