develooper Front page | perl.perl5.porters | Postings from July 2001

Re: Help needed with weakrefs.

Thread Previous
Nathan Torkington
July 2, 2001 09:08
Re: Help needed with weakrefs.
Message ID:
I've got WeakRef issues with 5.6, too.

  #!/usr/bin/perl -w

  use WeakRef;

  sub build {
    my $child = { NAME => Nat };
    my $parent = { NAME => Barry, CHILD => $child };
    $child->{PARENT} = $parent;
    weaken ($child->{PARENT});
    return $parent;

  for ($i=0 ; $i < 3; $i++) {
    my $person = build();
    print "$person\n";

I expect to see build() reuse $parent and $child:
 * $person holds the parent, which goes out of scope at the end of the loop
 * as the child reference to the parent doesn't count
 * the parent should be destroyed
 * and with the parent goes the last link to $child
 * so $child should be destroyed too.

But I don't see the reuse of $parent and $child.  Are WeakRefs really


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About