Design Proposal: IsViewCacheEnabled Improvements
See original GitHub issueRecently we’ve encountered a weird bug https://github.com/AndreiMisiukevich/CardView/issues/225. It turned out that the IsViewCacheEnabled
flag is working not like we were expecting and there are potential issues with the current implementation.
Current implementation
When the IsViewCacheEnabled
is set to false
, the lib creates multiple view instances of the same card. All these instances are bound to the same model and listen for updates. This is not efficient from the memory and performance points of view and in rear cases, like in https://github.com/AndreiMisiukevich/CardView/issues/225, leads to crashes.
Proposal
At any point of time there should be only one view instance for a certain card. E.g. if the user views the card with the index 2, there are 3 views created: for indices 1, 2, 3 (in case if we need one prev/next cards). So:
PrevView: 1 Current: 2 NextView: 3
When the user navigates to the card with the index 3, the lib destroys the view for the index 1, reuses the view 2 for the PrevView, reuses the view 3 as the Current and creates a new view for the index 4.
[Unbound and destroyed] 1 PrevView: 2 (reused) Current: 3 (reused) NextView: 4 (newly created)
If the user navigates back to the second card - the view 4 is destroyed and the view 1 is created. And so on.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
Top GitHub Comments
Nah, IMO it’s better to omit that value. So the lib can have it’s own enum that mimics the first two options from CachingStrategy.
i think we should add new property and mark old as obsolete