Any time you copy a reference into a new variable, the reference count is incremented. This is true when copying a weak or strong reference.
my $obj = {}; # 1 reference to {} stored in $obj
my $copy = $obj; # 2 references
weaken $obj; # 1 reference
at this point, if $copy
goes out of scope, the reference count will fall to zero, and the memory will be freed. Now assume the following code:
my $newref = $obj; # 2 references
undef $copy; # 1 reference
If Perl preserved the weak reference in $newref
, then the hash would be unexpectedly dealocated when $copy
was cleared. This would break the expectation that when you copy a reference, it will at least stick around as long as the copy.
In short, if weak references persisted across an assignment, it would force you to litter your code with myriad weakness checks, and would require some other way to unweaken a variable, all to avoid the inevitable variable suicide issues.