On Mon, 7 Aug 2006, Florian Ragwitz wrote:

> Hello there,
> 
> I wrote bindings for a small C library using XS. In those bindings I map
> some c structures to a perl objects, which are blesed into
> "Audio::XMMSClient".
> 
> The new() method allocates a new c structure structure and my bindings
> wrap it into an object. Now I'd like to free the memory allocated in
> new() when the perl object isn't used anymore.
> 
> DESTROY seems to be the way to do that. So I defined a DESTROY method in
> my XS code:
> 
>   void
>   DESTROY(c)
>           my_c_structure_t* c
>       CODE:
>           my_c_structure_unref(c);
> 
> 
> Unfortunately DESTROY won't be called when the perl objects reference
> count reaches zero as it seems to be the case in pure-perl world. What's
> the difference between pure-perl code and XS code with regard to
> DESTROY? How can I get my XS DESTROY method called properly?

DESTROY is not necessarily called at the time the refcount hits zero.  
Perl cleans up objects without references only when leaving a scope.  If 
you need more immediate action, just undef them yourself at the point 
they're no longer needed.

Steve

Reply via email to