![]() |
|
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?? |
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.
In Section
Seekers of Perl Wisdom
|
|