The problem with not using weaken has been explained.
But there's also a problem with using weaken.
sub d { my $dir = Practice::Dir->new; my $file = Practice::File->new; $dir->add_file($file); $file->add_dir($dir); return $dir; } sub f { my $dir = Practice::Dir->new; my $file = Practice::File->new; $dir->add_file($file); $file->add_dir($dir); return $file; } # This works fine. # `$dir` is a dir with one file. my $dir = d(); # XXX This fails. # `$file`'s dir is `undef` even though it wasn't before we returned. my $file = f();
The correct solution could be neither.
In reply to Re: Should I use weaken on an object attribute containing a reference to an object which contains reference back to original object?
by ikegami
in thread Should I use weaken on an object attribute containing a reference to an object which contains reference back to original object?
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |