in reply to Re: Tracing zombie variables.
in thread Tracing zombie variables.

Bah, I write stuff with cyclic refs all the time. Many useful data structres include cyclic refs. For instance I shall be posting my threaded treap implementation in the next few days and it has cyclic refs galore, all of which are correctly removed by using the correct DESTROY() subroutine (in fact my answer to ash was based on a solution I came up with to ensure that I wasnt leaking memory...)

:-)

Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)

Replies are listed 'Best First'.
Re: Re: Re: Tracing zombie variables.
by d_i_r_t_y (Monk) on Aug 30, 2002 at 03:48 UTC

    indeed. cyclic references *can* be a bitch though, especially in situations where one has a lot of inter-operating objects in a persistent Perl interpreter, eg mod_perl. consider:

    #!/usr/bin/perl -w use strict; package A; { sub new { my $class = shift; return bless( { @_ }, $class ); } sub DESTROY { warn "$_[0] just died"; } sub set { $_[0]->{ $_[1] } = $_[2]; } } package B; { @B::ISA = qw/ A /; } package C; { @C::ISA = qw/ A /; } package main; warn "doing something...\n"; do_something(); warn "doing something else (again)...\n"; do_something(); warn "exiting program...\n"; exit; sub do_something { warn "entering block...\n"; my $a = new A (); my $b = new B (); my $c = new C (); $b->set( C => $c ); $c->set( B => $b ); warn "exiting block\n"; } # output of above: doing something... entering block... exiting block... A=HASH(0x804b424) just died at ./test_objects.pl line 13. doing something else (again)... entering block... exiting block... A=HASH(0x805d074) just died at ./test_objects.pl line 13. exiting program... C=HASH(0x805bb10) just died at ./test_objects.pl line 13 during global + destruction. B=HASH(0x805b9f0) just died at ./test_objects.pl line 13 during global + destruction. C=HASH(0x805d08c) just died at ./test_objects.pl line 13 during global + destruction. B=HASH(0x804b424) just died at ./test_objects.pl line 13 during global + destruction.

    Voila, an unclaimed cyclic reference every time you call do_something(), or any other code that creates object that store references to each other. This is surprisingly easy to do in a large, multi object/reference system, and irritatingly difficult to track down when it happens. meanwhile, your httpd's are growing and growing with every page request....

    matt