Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Do subroutine variables get destroyed?

by Tanktalus (Canon)
on May 08, 2016 at 04:50 UTC ( [id://1162460]=note: print w/replies, xml ) Need Help??


in reply to Do subroutine variables get destroyed?

Everything in perl is on the heap (*). Variables are created when necessary (my variables are created when the my statement executes), and cleaned up as soon as there are no references left to them.

This allows you to create new hashes, arrays, etc., in your sub, and then return references to them and have them still work.

Compared to C, this is basically perl calling malloc for you for each variable declaration, and then calling free automatically not when the variable goes out of scope, but when there are no more references to that variable.

(*) Not quite true. But close enough for our purposes.

  • Comment on Re: Do subroutine variables get destroyed?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found