Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2018-12-14 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many stories does it take before you've heard them all?







    Results (69 votes). Check out past polls.

    Notices?