Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Beware of global variables, for they may prevent your destruction.

by JavaFan (Canon)
on Nov 25, 2009 at 22:00 UTC ( #809443=note: print w/ replies, xml ) Need Help??


in reply to Beware of global variables, for they may prevent your destruction.

Since I'd made a permanent reference to it in a package variable, it never got destroyed
That's not true. It will get destroyed at program termination, assuming your program terminates normally.


Comment on Re: Beware of global variables, for they may prevent your destruction.
Re^2: Beware of global variables, for they may prevent your destruction.
by kyle (Abbot) on Nov 25, 2009 at 22:12 UTC

    That's something I should have been more clear about. All this is taking place in a mod_perl setting. Previous to my change, the object was expected to be destroyed at the end of each request. Since my change, it would still live on between requests, until the next request came along and replaced it in the package variable (which is too late for the new object to benefit from the experience of the old object).

    Perhaps I could get away with saying that "never" is an exaggeration. Strictly speaking, each one was destroyed, just not on time.

Re^2: Beware of global variables, for they may prevent your destruction.
by tilly (Archbishop) on Nov 29, 2009 at 23:38 UTC
    However destructors run at program termination often find that data they expected to have still around is not there. Such as data inside of the object you are destroying

    Therefore it is safer to deallocate globals in END blocks. That way you can control what is there. But be careful not to do anything that messes up $!, else exit may not work as expected.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-09-23 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (219 votes), past polls