Closed p5pRT closed 20 years ago
I am using weak references to manage a cache of objects that I have handed out to callers. This mostly works\, but given a certain combination of cooperating classes\, I see this during cleanup:
panic: magic_killbackrefs during global destruction.
This is the minimal reproducible case I can come up with:
$b = new broker; $anObj = $b->getobj();
package broker; sub new { return bless { pool => new pooler }\, 'broker' } sub getobj { my $self = shift; my $obj = bless {}\, 'obj'; $self->{pool}->add( 'x'\, $obj ); return $obj; }
package pooler; use WeakRef; sub new { return bless {}\, 'pooler' } sub add { my ( $self\, $key\, $ref ) = @_; push @{ $self->{ $key } }\, $ref; weaken $self->{ $key }[0]; return $ref; }
Either of the following after the top two lines will avoid panic:
undef $anObj; delete $b->{pool};
I tried many variants for pooler::add(). All of the following are substitutes for the middle two lines. All ought to have the same effect.
This one also causes the panic:
$self->{ $key } ||= []; my $a = $self->{ $key }; push @$a\, $ref; weaken $a->[0];
But neither of these do:
$self->{ $key } = []; my $a = $self->{ $key }; push @$a\, $ref; weaken $a->[0];
$self->{ $key } = [ $ref ]; weaken $self->{ $key }[0];
Many thanks for your time.
On Fri\, 30 Jun 2000 02:50:28 PDT\, Deneb Meketa wrote:
I am using weak references to manage a cache of objects that I have handed out to callers. This mostly works\, but given a certain combination of cooperating classes\, I see this during cleanup:
panic: magic_killbackrefs during global destruction.
This is due to the global destruction bug. The perl5-porters archives have lots of discussion on the subject\, but little real work.
Sarathy gsar@ActiveState.com
In \200006300950\.CAA15633@​deneb\.jumpdata\.com\, Deneb Meketa writes: :I see this during cleanup: : : panic: magic_killbackrefs during global destruction.
Please try this patch: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-06/msg00322.html .. which appears to fix the problem you encountered.
Hugo
Migrated from rt.perl.org#3450 (status was 'resolved')
Searchable as RT3450$