Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Scope of lexical variables in the main script

by davido (Cardinal)
on Apr 20, 2012 at 05:58 UTC ( [id://966087]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Scope of lexical variables in the main script
in thread Scope of lexical variables in the main script

Perl uses reference counting. In your case, inside the block,$tricky and $reference each own one reference to the scalar container that holds the string, "TRICKY". While inside the block, the reference count to the SV that holds the string "TRICKY" is two. After the block exits, $tricky goes out of scope, and the reference count drops by one, to one. As long as $reference remains in scope, the SV (the container for a scalar) holding the string "TRICKY" remains alive.

After $reference passes out of scope, assuming nobody else holds a reference to that scalar, the ref-count drops to zero. Perl regains that memory as available for future use. It's not released back to the OS.

Aren't you glad this isn't simple pointers in C or C++? :)


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (1)
As of 2026-03-12 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.