Unless I misunderstand the purpose of dispose I would expect memory to be released...

Yes. (Actually, it sounds like it's doesn't do anything on a system will a properly installed Scalar::Util because it's done automatically then.)

...and the size of the process to go down.

That does not follow. Freeing memory does not necessarily make the process size go down. It's only guaranteed to go back to Perl's free memory pool. In some circumstances on some OSes, the process size can go down, but there's no guarantee of it.

For example, you could observe the following:

my $x; $x .= "a" for 1..1024; # Process size goes up undef $x; # Process size doesn't go down $x .= "a" for 1..1024; # Process size doesn't go up

undef $x; freed the string's buffer — observable with Devel::Peek — but it might not release it to the OS. However, Perl will now be able to reuse that memory to rebuild $x.

To see if the memory is freed, what you need to do is use some memory and see if the process goes up. Do as almut suggested and call process twice in a row, checking the process size after each call.


In reply to Re^6: XML::Twig loves to eat my memory by ikegami
in thread XML::Twig loves to eat my memory by carcus88

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.