Help for this page

Select Code to Download


  1. or download this
        my $dad= My::Parent->new( name => 'Robert' );
        {
    ...
        # No direct access to Robert, now.  Garbage collection runs.
        # Robert and Bobby form a loop but both are unreferenced.
        # Both get destroyed.
    
  2. or download this
    package My::Parent;
    use My::Outer qw< ::Inner new DESTROY AUTOLOAD >;
    ...
    package My::Child;
    use My::Outer qw< ::Inner new DESTROY AUTOLOAD >;
    use overload '""' => \&GetName;
    
  3. or download this
    package My::Inner;
    
    ...
        my( $in )= @_;
        return --$in->{refs};
    }
    
  4. or download this
    # Outer objects:   dad          son  These are wrappers given to other
    +s
    #                   |            |   just to track what is still in-us
    +e.
    #                   v            v
    # Inner objects:  _dad <------ _son  These have the real data, includi
    +ng
    #                   `------------^   links to other (inner) objects.
    
  5. or download this
    package My::Child::Inner;
    use My::Inner qw< _wrap _unwrap _incRefs _decRefs >;
    ...
        my( $_son )= @_;
        warn "DESTROYing son: $_son->{name}\n";
    }
    
  6. or download this
    # Called when Son is no longer externally referenced:
    sub _free {
    ...
            $_son->{dad}= $_dad->{son}= undef;  # Break ref cycles!
        }
    }
    
  7. or download this
    sub _isRefd {
        my( $_son, $hvSeen )= @_;
    ...
        }
        return 0;
    }
    
  8. or download this
    sub _free {
        my( $_son, $force )= @_;
    ...
        }
        $_son->{dads}= [ ];
    }
    
  9. or download this
    {
        my $dad= My::Parent->new( name => 'Sr' );
    ...
        warn "Rest to be destroyed next.\n";
    }
    warn "Everything destroyed above.\n";
    
  10. or download this
    $dad=Sr
    $dad=Sr -> $son=Jr
    ...
    DESTROYing son: Jr
    DESTROYing dad: Fin
    Everything destroyed above.
    
  11. or download this
    #!/usr/bin/perl -w
    use strict;
    ...
    DESTROYing dad: Fin
    Everything destroyed above.