#2525 fix for detachAll so it supports cycles