Figure 4-1. When the references in a data structure form a loop, Perl's reference-counting system may not be able to recognize and recycle the no-longer-needed memory space
At this point, there are two names for the data in
@data1: @data1 itself and
@{$data2[3]}, and two names for the data in
@data2: @data2 itself and
@{$data1[2]}. You've created a
loop. In fact, you can access won with an infinite
number of names, such as
$data1[2][3][2][3][2][3][1].
What happens when these two array names go out of scope? Well, the
reference count for the two arrays goes down from two to one. But not
zero! And because it's not zero, Perl thinks there
might still be a way to get to the data, even though there
isn't! Thus, you've created a
memory leak. Ugh. (A memory leak in a program
causes the program to consume more and more memory over time.)