Skip to content

Commit

Permalink
Don't pass reference of batchOperation to closure to restore behavior…
Browse files Browse the repository at this point in the history
… before c7c79c7 (#116)

c7c79c7 introduced a regression: 
The completion closure of
`UICollectionView.performBatchUpdates(_:completion:)` has a strong
reference to `batchOperation`. This causes that the `batchOperation`
stays longer in memory as the collection view itself.

A symptom of this is that `MainCollectionViewContext.apply(update:)`
might get called while the `adapter` is deallocated already.

This PR restores behavior to the state before
c7c79c7 by just referencing the
`completion` closure instead of `batchOperation`.
  • Loading branch information
HeEAaD authored Apr 25, 2024
2 parents 264ec44 + 0002569 commit a59e6bf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions SectionKit/Sources/Utility/UICollectionView+Apply.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ extension UICollectionView {
if reloads.isNotEmpty {
reloadItems(at: reloads.map { IndexPath(item: $0, section: section) })
}
}, completion: { batchOperation.completion?($0) })
}, completion: { [completion = batchOperation.completion] in
completion?($0)
})
}
}

Expand Down Expand Up @@ -108,7 +110,9 @@ extension UICollectionView {
if reloads.isNotEmpty {
reloadSections(IndexSet(reloads))
}
}, completion: { batchOperation.completion?($0) })
}, completion: { [completion = batchOperation.completion] in
completion?($0)
})
}
}
}

0 comments on commit a59e6bf

Please sign in to comment.