In short, your code is working fine. As expected, when the cells scroll from the screen, they are ultimately marked as reusable. And when you call dequeueReusableCellWithReuseIdentifier , if there is a cell available for reuse, it will do it. If not, he creates one.
The time you see a lot of cells being created is scrolling quickly or continuously. But if you make short small scrolls, release, pause, let the user interface catch up and repeat, then you will see very few created cells.
I interpret this as meaning that iOS prioritizes the user interface and the creation of new cells to delete old cells, which allows them to be reused. Therefore, if you switch quickly, it has problems finding and placing old cells available for reuse. This is probably not entirely bad, as it is probably what gives the collection such a smooth flow. Marking old cells for reuse is one of the less important things for iOS. But it is clear that if the memory is dense, it can be a problem.
By the way, if you put NSLog in dealloc , you will also notice that when the user interface finally catches up after a very fast scrolling of the collection, it clearly has logic that says "Lord, I have more spare cells than I really need, I will get rid of from some of them. " This is actually a pretty smart implementation. Focus on speed, but with some memory optimizations that occur when the user interface closes.
Rob
source share