Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by Joost (Canon)
on Dec 10, 2004 at 16:08 UTC ( [id://413892]=note: print w/replies, xml ) Need Help??


in reply to Do I need to free allocated space in an END sub?

Your problem isn't with mod_perl per se, but with Apache::Registry - it calls END blocks at the end of each request, probably to accomodate sloppy coding :-)

Maybe you could put an object in a global at BOOT time, and hang a DESTROY method on that object. As long as you don't remove the object during normal runtime, it should be destroyed when the interpreter exits (and DESTROY should be called then).

For other options, see Apache::ChildExit.

  • Comment on Re: Do I need to free allocated space in an END sub?

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

      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.

Re^2: Do I need to free allocated space in an END sub?
by shay (Beadle) on Dec 10, 2004 at 18:17 UTC
    Having an object to DESTROY seems like a neat idea, so I'll try that.

    Thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-19 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found