Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by hakkr (Chaplain)
on Dec 10, 2004 at 16:30 UTC ( [id://413896]=note: print w/replies, xml ) Need Help??


in reply to Re: 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 mean going by the logic that the BEGIN is only executed once when the script is loaded into memory, I would assume that the END is also only executed once when it leaves memory i.e the interpreter ends not the request.

that'll teach me to assume eh. regarding your problem I think you are probably right perls own garbage collection will hopefully save you the bother. .... This was annoying me, so google yielded this understanding mod_perl environments

Replies are listed 'Best First'.
Re^3: Do I need to free allocated space in an END sub?
by Joost (Canon) on Dec 10, 2004 at 16:54 UTC
    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.

Re^3: Do I need to free allocated space in an END sub?
by shay (Beadle) on Dec 10, 2004 at 18:22 UTC
    Did you mis-read? I have a BOOT: section (an XS keyword), not a BEGIN sub.

    END is called for each request if the module was loaded by the Apache child process. If it is preloaded by the server process (e.g. PerlModule line in the httpd.conf file) then the END is only run once when the server shuts down. This is fine, except that it isn't possible for a source filter module, which, as I said, is necessarily loaded by the child when loading the script.

    Unless, of course, you have the server pre-load the script (?)

    Anyway, I wanted a more "natural" solution that doesn't require the user to have loaded the script/module at some particular time.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-03-28 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found