Unset array and entity reference after loop