Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by JavaFan (Canon)
on Nov 25, 2009 at 22:00 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://809443]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-03-19 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found