Like ‘almut’ said the DESTROY method doesn’t work as expected so I begin to write a subroutine in the hope of finding a solution to the memory leak problem…
I think I’m almost there however after tracing the execution with ‘Devel::Trace’ I found that the execution order is STEP1; STEP2 and then STEP4, and should be STEP1;STEP2;STEP3.

If the program reached the last return statement why is it going to STEP4 and not to the main function? Could anyone tell me what is going out?

#!/usr/bin/perl -w use strict; use Tree::Simple; #use Tree::Simple 'use_weak_refs'; use Data::Dumper; #use Devel::Trace; $Data::Dumper::Indent=1; #$Devel::Trace::TRACE=0; local $|=1; my $CR="\n"; my $WS="-------------------------------------------------------------- +---$CR"; my @array = qw/ 112.75 850.22 100.65 /; #for (my $j=0;$j<1;$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; print "${WS}DATA DUMPER: $CR"; print Dumper $tree; print "${WS}"; FULLY_DESTROY($tree); ###########################STEP 3############################ print "${WS}DATA DUMPER: $CR"; print Dumper $tree; #$tree->traverse(sub { my($_tree)=@_; #print (("\t" x $_tree->getDepth()), $_tree->g +etNodeValue(),"\n"); #}); undef $tree; # } <STDIN>; #pause sub printleaf{ my ($_leaf)=$_[0]; print("VALUE: ",$$_leaf->getNodeValue()," | ROOT?: ",$$_leaf->isRo +ot() ? "true" : "false"," | DEPTH: ",$$_leaf->getDepth()," | INDEX: " +,$$_leaf->getIndex(),"$CR"); } sub FULLY_DESTROY{ my ($self)=$_[0]; print ($self->getNodeValue()," "); while(1) { ###########################STEP 4############################ if(!ref($self->{_parent}) && $self->{_parent} eq 'root' && sca +lar(@{$self->{_children}})==0) { $self->{_parent} = undef; print ("called last to end the sub routine$CR"); ###########################STEP 1######################### +### last; } if(defined($self->{_children}) && $self->getChildCount!=0) { print ("childs ",$self->getChildCount(),"$CR"); FULLY_DESTROY($self->getAllChildren()); } #if has no childs saves the father reference my $ref; my $index=$self->getIndex(); print("index ",$index," "); if(($index+1) == ($self->getParent()->getChildCount())) #last +in the branch { print ("childs 0 last in branch$CR"); $ref = \$self->getParent(); $self->{_parent} = undef; @{$$ref->{_children}}=(); FULLY_DESTROY($$ref); } else { print ("childs 0 not last in branch$CR"); $ref = \$self->getSibling($index+1); $self->{_parent} = undef; FULLY_DESTROY($$ref); } } ###########################STEP 2############################ print "end should return to main function$CR$CR"; return; }

In reply to Re: Simple Program Huge Problem by crusher
in thread 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.