threads::shared::_refcnt offers an alternative to the Scalar::Util::weaken approach (although objects must be share()d): my $xs_dtor = \&SharedXSObject::DESTROY; *SharedXSObject::DESTROY = sub { return unless @_ and threads::shared::_refcnt($_[0]) == 1; # okay -- this is really the last ref to the underlying object! &$xs_dtor; } I use this for safe DESTROYment of XS-backed objects without any CLONE bookkeeping -- not only to avoid double free()ing, but specifically to prevent the premature invalidation/shutdown of the underlying system resources. -MikeThread Previous | Thread Next