Florian Ragwitz <[EMAIL PROTECTED]> writes: >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?
None as far as I know. Are you sure REFCNT has gone to zero? Most common reason for DESTROY not being called is accidental REFCNT too high. >How can I get my XS DESTROY method called properly? > > >TIA, >Flo