in reply to Re^4: Garbage collection at subroutine return
in thread Garbage collection at subroutine return

True, but slightly different.

Your approach is correct if the goal is to construct a one-off structure and pass it back to the caller, surviving until the caller is done with it. Useful if the function generates some kind of custom hash mapping, for example.

My approach is correct if the intent of myhash is to be some kind of persistent structure internal to the mechanics of DoIt, perhaps some kind of memoization cache or other internal structure.

They're both useful, it all depends on what the original intent was (which is a bit hard to discern from the question).


Mike
  • Comment on Re^5: Garbage collection at subroutine return