An application I am writing uses a lot of memory and there seem to be a serious memory leakage I try to track down. As I am far from being a memory expert I wonder if even I am looking at the right numbers and if the baseline information is correct? I am using the following script to check its own memory usage:
#!/usr/bin/perl use strict; use warnings; print_size('empty'); foreach my $module ( 'Data::Dumper', 'Scalar::Util', 'Getopt::Long', 'Net::XMPP', 'JSON::XS', 'LWP::UserAgent', 'POE qw(Component::Server::TCP)', 'Moose', ) { eval "use $module"; die $@ if $@; print_size("after $module"); } sub print_size { my ($msg) = @_; my @lines = qx{/bin/ps -e -o pid,ppid,vsize,rss,command | grep ^$$ +}; chomp @lines; foreach my $line (@lines) { my ($pid, $ppid, $vsize, $rss) = split /\s+/, $line; print "VM: $vsize RSS: $rss - $msg\n"; } return; }
and when running on SuSE with perl 5.10.0 I get the following data:
VM: 15972 RSS: 2324 - empty VM: 18740 RSS: 3256 - after Data::Dumper VM: 20968 RSS: 3388 - after Scalar::Util VM: 21760 RSS: 4240 - after Getopt::Long VM: 51348 RSS: 15408 - after Net::XMPP VM: 53648 RSS: 15588 - after JSON::XS VM: 57980 RSS: 17704 - after LWP::UserAgent VM: 65852 RSS: 21572 - after POE qw(Component::Server::TCP) VM: 88616 RSS: 31924 - after Moose
So if I understand correctly my script starts - after loading all the necessary modules - with 88 Mb memory used? Do I see correctly that loading Moose take 20Mb without even creating classes and objects? Net::XMPP is even bigger as it takes 30Mb ? Is the way I am measuring correct? As I'll need to run several instances of this process at the same time will they share some memory or will this number just be multiplied by the number of processes I have?

In reply to memory usage and leakage by szabgab

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.