Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearing data frequently while delegate / dataSource is changing within collection view can cause crashes #1155

Open
maicki opened this issue Oct 2, 2018 · 2 comments

Comments

@maicki
Copy link
Contributor

maicki commented Oct 2, 2018

Silently clearing its data while the collection view is still being used, without notifying the backing UICollectionView, puts it out-of-sync and causes mayhem next time the collection view processes a batch update. If you look at the stack trace closely, you'll notice that the crash doesn't occur on the same run loop that clearData was called, making it extremely tricky to investigate and identify the root cause.

46322275-c413c480-c59c-11e8-9ede-172f435e2cde

@maicki
Copy link
Contributor Author

maicki commented Oct 2, 2018

The original reason for why this clearing data was added is to ensure that the interfaceState is zero’d out in the collection dealloc case.

@nguyenhuy What do you think, would it be enough to call reloadData on the collection itself in this case, or at least invalidateLayout? After really making sure the reason for the crash in the stack trace is clearing the data as we talked in the past we should look what the root cause is in the first place.

@nguyenhuy
Copy link
Member

I kind of get the issue. But I think it would be best to have a stacktrace when it occurs.

I can imagine that when the cell node are deallcoated at the end of the hosting collection view lifecycle, their interface state aren't updated properly because we never do so. A proper fix would be to directly/indirectly update those states. Directly means walking through all (visible) cell nodes and set manually reset the state. Indirectly means somehow trigger the collection view to update its dataset and ranges, for example by calling reload data as you suggested above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants