Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: How aggressively does Perl clean up when you exit()?

by Aristotle (Chancellor)
on Nov 15, 2001 at 01:26 UTC ( #125425=note: print w/replies, xml ) Need Help??

in reply to How aggressively does Perl clean up when you exit()?

There is a fine difference to note here.

On the one hand you have the "standard" resources - memory, file handles and the like; these resources are provided by the interpreter as it executes your script. These resources are also guaranteed to be cleaned up on exit() (so long as you're not dumping core or something).

Then there's "external" resources the code in execution may have allocated - like, a database driver may have asked the database to allocate a handle. These resources will not be released automatically, rather, the code in question has to make sure they are returned. In case you're using CPAN modules, it is safe to assume that, bugs aside, all of them clean up behind themselves.

As has been mentioned, you may want to look into what END { } and DESTROY { } do: define a blocks of code that will always be executed the end of the program or when the corresponding object goes out of scope, respectively. This is (almost) regardless of how you fall out (of the program or scope). Properly written modules (such as the ones available on CPAN :)) use these to make sure they neatly clean up after themselves.

Long reply, short point: yes. You can use exit() to fall out of your scripts at whichever point you choose.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2020-01-19 19:31 GMT
Find Nodes?
    Voting Booth?