On Mar 11, 2009, at 5:58 AM, Gregor Goldbach wrote:

Hi everyone,

I understand initialization of an XS module may be modified using BOOT.
However, there seems to be no counterpart of BOOT. How do I e.g. free
memory I allocated in BOOT?

Is it okay to call call_atexit() for this purpose? DynaLoader does it...
If I may use this function, why isn't it documented in perlapi? ;)

Or is the current practice to write an XS function that e.g. frees the
memory allocate at BOOT and call it in an END handler in the module's
Perl code?

Sorry if this is a FAQ but I couldn't find anything in the docs about it...



It depends, really.

If your BOOT code creates perl objects that need to be cleaned up, or hangs on to anything that depends on perl objects, then atexit() is too late. atexit() handlers get called after main() returns, and by that time, the interpreter has already shut down.

If all you need to do is clean up stuff you malloc'd, or sockets or files or shm or whatever you created from C, then atexit() should be fine.

An END block would be a cleaner, more general solution, IMO, because you don't have to worry about your C teardown eventually trying to call back into a dead interpreter.


--
So this new album took us quite a while, to get it together, to find a title and things like that - and we were travelling quite a bit - we made a few sort of gestures in the East, and a few gestures in the West, and then we got thrown out because of our gestures - this is something that we decided was an apt title for a thing that's called 'The Song Remains The Same'.
  -- Robert Plant, rambling to introduce a song

Reply via email to