- my creates a new hash (like new would in another language). The sub holds a references to the hash, so the hash's REFCNT is one.
- You create a reference to the hash, so the hash's REFCNT increases to two.
- You exit the sub, so the sub release its reference to the hash, so the hash's REFCNT drops to one. (If it wasn't for the reference you created, the hash's REFCNT would now be zero, and the hash would get freed.)
- If/when you eventually destroy the reference, the hash's REFCNT will drop to zero, freeing the hash (and in turn reducing the REFCNT of its values, possibly freeing them).
(The actual implementation is somewhat more complicated, but the differences aren't relevant here.)