Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi Monks, I'm trying to understand the garbage collector. Please have a look at my code example:

#!/usr/bin/perl use strict; use warnings; package Foo; sub new { my $self = bless { }, shift; for (1..2_000_000) { $self->{x} .= "x" x 1000; } return $self; } package Bar; sub new { my $self = bless { }, shift; for (1..2_000_000) { $self->{$_} = "x" x 1000; } return $self; } package main; print "### Test Foo\n"; my $foo = Foo->new; print "Object created\n"; print "Size: ", qx{ps -p $$ -o rss=}; $foo = undef; sleep 3; print "Object destroyed\n"; print "Size: ", qx{ps -p $$ -o rss=}; print "### Test Bar\n"; my $bar = Bar->new; print "Object created\n"; print "Size: ", qx{ps -p $$ -o rss=}; $bar = undef; sleep 3; print "Object destroyed\n"; print "Size: ", qx{ps -p $$ -o rss=};
Output:
### Test Foo
Object created
Size: 1955472
Object destroyed
Size:  2348
### Test Bar
Object created
Size: 2647552
Object destroyed
Size: 2631164

The Foo example is that what I expect. But I don't understand why the memory is not releases back to the operating system in the Bar example.

Could someone bring some light into my darkness?

Cheers, Jonny

In reply to Memory is not released back to operating system by bloonix

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2014-07-11 11:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (224 votes), past polls