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

Re: Help needed with weakrefs.

Thread Previous
From:
Nathan Torkington
Date:
July 2, 2001 09:08
Subject:
Re: Help needed with weakrefs.
Message ID:
15168.40046.688000.903860@gargle.gargle.HOWL
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
working?

Nat



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About