in reply to Why does Perl allow you to return array references to variables in local scope?
I think the easiest way to think of it is that: names have scope; data lives as long as it is referenced.
So whilst the name @arr has gone out of scope; the data that it labeled whilst in-scope, continues to persist, because a reference to it was returned to the caller.
Hence, if you call DoSomething() in a void context - ie. you don't assign the return reference to a name in the calling scope -- then the returned reference will be discarded, and the data it references -- formerly known as @arr -- will no longer be referenced and so will be returned to the process memory pool for reallocation.
|
|---|