http://qs321.pair.com?node_id=413908


in reply to Re^2: Do I need to free allocated space in an END sub?
in thread Do I need to free allocated space in an END sub?

If BEGIN is not called for each request then how the come END is?

I think the reason is, that Apache::Registry is meant to make it easy to run CGI scripts as mod_perl scripts. Since END blocks in CGI scripts are run after each request, they also run after each request when using Apache::Registry. I don't like it either, but apparantly, that's how it is.

As for BEGIN blocks: if you really want to run them at the right time, you'd have to remove all the loaded code and variables from the interpreter before handling the request (and then reload all the code) - it would probably make Apache::Registry scripts almost as slow as normal CGI scripts.