Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^4: How to deal with the fact that Perl is not releasing memory

by BrowserUk (Pope)
on Jul 07, 2013 at 15:38 UTC ( #1042986=note: print w/replies, xml ) Need Help??

in reply to Re^3: How to deal with the fact that Perl is not releasing memory
in thread How to deal with the fact that Perl is not releasing memory

It is genuinely my understanding that declaring the variable within one (in-lined) sub, but using it in another, is Not A Good Thing.

Each of the anonymous subs has its own my @messages = (); statement. They are not related!(*) They do not name the same memory space (though they may well re-use some or all of the same memory at different times).

By moving the declarations outside of the subroutines, you would make them occupy the same memory and never be cleaned or re-initialised and thus they would grow unchecked and totally exacerbate the very problem your "advice" was intended to help with. (Presumably; you do not seem deliberately malicious; just <you pick the adjective>.)

(*)Each time any of the subs gets called, they get a new instance of that array, which is then discarded -- its memory space given back to the process memory pool for reuse -- when the call to the subroutine ends. The fact that they are used for similar purposes in each the 3 subroutines, and therefore are given similar names, does not mean that they have anything whatsoever in common.

(In fact, the initialisation is completely redundant, a clean, empty array is created each time the subroutines are called.)

This is how lexical (my) variables work. The fact that you don't know this beggars belief. The fact that you don't know this but still feel qualified to offer others advice, beggars disbelief!

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1042986]
Tanktalus envisions a train wreck.
Tanktalus snickers. :D

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-03-21 19:07 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (270 votes). Check out past polls.