#2525 fix for detachAll so it supports cycles
Merge pull request #3071 from wouterv/detachAll-cycle-fix

#2525 fix for detachAll so it supports cycles