Hi,

I’m experiencing a strange behavior while executing this script (that I made especially to help me track what appears to be a memory leak):

#!/usr/bin/perl -w use strict; use Tree::Simple; my $CR="\n"; my @array = qw/ 112.75 850.22 100.65 1651.82 21.82 1598.36 962.97 15.1 +0 85.55 112.75 850.22 21.82 1651.82 1598.36 962.97 /; for (my $j=0;$j<10**10;$j++) { #always the same code to execute my $i=0; my $tree = Tree::Simple->new("root tree",Tree::Simple->ROOT); printleaf(\$tree); $tree->addChild(Tree::Simple->new("$array[$i]")); printleaf(\$tree->getChild(0)); my @_auxarray=@array; splice(@_auxarray,$i,1); foreach my $elem (@_auxarray) { printleaf(\Tree::Simple->new("$elem",$tree->getChild(0))); } undef @_auxarray; $tree->DESTROY(); #clear circular references $tree->traverse(sub { my($_tree)=@_; print (("\t" x $_tree->getDepth()), $_tree->ge +tNodeValue(),"\n"); }); undef $tree; } my $pause=<STDIN>; #variable only used to pause the program sub printleaf{ my ($_leaf)=$_[0]; print("VALUE: ",$$_leaf->getNodeValue()," | ROOT?: ",$$_leaf->isRo +ot() ? "true" : "false"," | DEPTH: ",$$_leaf->getDepth()," | INDEX: " +,$$_leaf->getIndex(),"$CR"); }

Every time that the loop repeats, the memory usage increases even if I undef the reference to the object.

For what I know if an object loses all its references the “perl garbage collector” should automatically destroy it and free the memory, right?

Could someone help me and tell me if I’m making any mistake?


I’m using ActivePerl 5.10 B1004 and the module Tree::Simple version 1.18.

In reply to Simple Program Huge Problem by crusher

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.