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

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

by Aristotle (Chancellor)
on Nov 15, 2001 at 01:26 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2025-06-22 18:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.