Some garbage collectors have loop detection; Perl, for performance and historical reasons, no. If you need a link that does not affect the link count, you can use Scalar::Util::weaken to get a weak link, which eliminates the need for loop detection in most situations where you need to rely on it. Loop detection should be detected in the interpreter to automatically determine if \$a should be a weak or strong reference, so you just need to do this explicitly.
source share