MvvmCross / MvvmCross-AndroidSupport

Android support library packages for MvvmCross: The .NET MVVM framework for cross-platform solutions.
http://mvvmcross.com
15 stars 0 forks source link

Clear bindings on ViewHolders when the RecyclerView is detached. #273

Closed kjeremy closed 8 years ago

kjeremy commented 8 years ago

Keep WeakReferences of all ViewHolders created by the adapter. When the associated RecyclerView is detached from the window we clear the bindings. Note that this does not Dispose of the ViewHolder since the Adapter doesn't really manage the lifetime of the ViewHolder and there is no callback for when the ViewHolder is destroyed.

Without this we leak target bindings.

Fixes https://github.com/MvvmCross/MvvmCross/issues/1379

kjeremy commented 8 years ago

Note that I also tried creating my own RecycledViewPool where we clear the bindings on Clear but that didn't help. I have a feeling that if someone wanted to share views between adapters/recyclerviews they'd have to customize the RecycledViewPool as well so maybe we shouldn't really worry about someone sharing views right now.

Cheesebaron commented 8 years ago

I don't see a lot of cases where you would want to share the RecyclerViewAdapter between shown views on the screen anyways.

I think this is good as is. Then we can take the edge case of sharing views in the future.