public void UpdateViews(List <CellData> cells) { HashSet <long> ids = new HashSet <long>(); HashSet <long> idsToRemove = new HashSet <long>(); foreach (var cell in cells) { if (cellViews.ContainsKey(cell.id)) { // Update CellView view = cellViews[cell.id]; view.BindData(cell); } else { // Add new AddView(cell); } ids.Add(cell.id); } // Prepare list of not existing cells foreach (var entityId in cellViews.Keys) { if (ids.Contains(entityId) == false) { idsToRemove.Add(entityId); } } // Remove not existing cells foreach (var entityId in idsToRemove) { EntityView view = cellViews[entityId]; cellViews.Remove(entityId); Destroy(view.gameObject); } }