On Wed, Mar 11, 2009 at 07:28:34PM -0400, muppet wrote:
> 
> 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.

Yes, but perl objects are going to be cleaned up (or at least, any with
DESTROY methods are going to get it called) before then, so that's somewhat
a red herring.

But possibly also a solution - anything allocated in BOOT that is stashed
inside an object will get that object's destroy method called soon after
END time, with a live interpreter. Or as live as the interpreter is during
global destruction. (Global destruction order is not to be relied on, so
things you expected to be there because they were, well, global, might not
any more)

Nicholas Clark

Reply via email to