Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Do subroutine variables get destroyed?

by GrandFather (Saint)
on May 08, 2016 at 07:06 UTC ( #1162471=note: print w/replies, xml ) Need Help??

in reply to Do subroutine variables get destroyed?

I see where your C/C++ influence gets you a variable called gptr, but in Perl there are no pointers. A better name is gref. So, to elaborate on Tanktalus's reply a little: Perl variables are reference counted and garbage collected, so when you reference %hsh with $gref Perl bumps the reference count on %hsh. %hsh was created with a reference count of 1 and the count is decremented when %hsh goes out of scope. However by the time %hsh goes out of scope the reference count has been incremented due to the reference assignment to $gref so the storage remains in use until $gref either goes out of scope or is assigned a new value.

For the vast majority of Perl scripts you needn't be concerned about memory management and that significant bane of C, invalid memory accesses, essentially can't happen.

Premature optimization is the root of all job security
  • Comment on Re: Do subroutine variables get destroyed?

Replies are listed 'Best First'.
Re^2: Do subroutine variables get destroyed? (Deterministic Destructor References)
by eyepopslikeamosquito (Bishop) on May 08, 2016 at 16:37 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1162471]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2023-03-28 12:07 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (67 votes). Check out past polls.