sub DESTROY { my ($self) = @_; delete $my_objects{$self}; # We run the destruction in eval, as Perl sometimes produces an error # message "Can't call method "FETCH" on an undefined value" when the # destructor is called a second time. eval('xs_DESTROY($self)'); unless ($@) { # We must clear internaldata, since Perl calls the destructor twice, but # on the second occasion, the XS code has already deallocated internaldata. # The XS code has problem with setting values in stored hashes, why we do # it. This assignment cannot be in eval, since the STORE method only # permits DESTROY to change internaldata. $$self{'internaldata'} = 0; } }