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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |