Ensure unused reference is removed when elements are removed.