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

Re: How to avoid closures and memory leaks.

by LanX (Saint)
on Oct 18, 2014 at 11:12 UTC ( [id://1104226]=note: print w/replies, xml ) Need Help??


in reply to How to avoid closures and memory leaks.

Use a my declaration before using a var in your subs, then you'll "avoid closures".

See also Coping with Scoping

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

PS: Maybe a case of how (not) to ask a question ?

Replies are listed 'Best First'.
Re^2: How to avoid closures and memory leaks.
by runnerup (Novice) on Oct 18, 2014 at 14:43 UTC
    Will this avoid closure?

    my $test = "a";

    sub test {
    my $temp = $test;
    }

    Will $temp avoid closure?
      well if you meant $temp instead of $test ... YES!

      my $temp = "a"; sub test { my $temp = $test; }

      please read the link provided about Coping with Scoping and please use <code> tags!

      update

      Basically does a my variable (aka lexical) belong to the surrounding '{ BLOCK }'.

      A sub's (or an if's) body is a { BLOCK } and the file itself (i.e w/o surrounding curlies) is practically the top-level block.

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-28 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found