in reply to Reference to a non-primitive (e.g. hash) local function variable is returned to the caller

This is why Perl uses reference counting. Perl knows what memory is still referenced and keeps it alive, no matter where it is referenced from (within Perl). Allocating and passing around values this way is a best practice in Perl, while it may or may not be a best practice in other languages with unmanaged memory, like C.

  • Comment on Re: Reference to a non-primitive (e.g. hash) local function variable is returned to the caller