Does it make sense to check here for whether the refcount is currently 1, i.e. we don't really need to detach after all ?  If that's something all the callers are doing before calling this, it might be better checked here.