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
Protect Android Bindings #1446
Protect Android Bindings #1446
Conversation
Fixes memory issues with the Android Support Library Removes hack that tracked ViewHolders.
I just looked through this. It seems to achieve the same thing I did in one of my PR's but ran into the issue that EventHandler cannot be cast to EventHandler, which lead to some issues with detecting whether the Event was present on the View, through reflection. This seems like a nice way of tackling this and makes Android bindings weak, yay! I'll give this a spin soon 👍 |
I spent a LOT of time trying to figure out why C# can't tell the difference between I'm not sure if the other platforms should also weak subscribe to their event handlers as well (separate change). What makes Android special is that you can get into this weird undead (but not zombie) object state. |
Something is up with SelectedItem binding for MvxRadioGroup. It doesn't work until I change the FillTargetFactories registration from MvxRadioGroup to RadioGroup. After that change it triggers. However, a new problem appears:
EDIT: Just changed the casts to RadioGroup in the MvxRadioGroupSelectedItemBinding and it magically works again? What the heck is going on? I am using MvxRadioGroup in my axml file... Why does the cast not work? EDIT EDIT: Apart from this strangeness with MvxRadioGroup, I think this is good to go when merge conflict has been resolved. I've tested with the APIExample where I added explicit GC on all property changed, which does not seem to break bindings. |
I bet you that |
Aw crap! You might be right! I guess it is good then. These changes to use WeakSubscribe instead should ofc also be present in AndroidSupport. |
There is a PR open for that (MvvmCross/MvvmCross-AndroidSupport#300). Also: I'm surprised that binding worked for |
SelectedItem binding will only work on MvxRadioGroup because of the way MvxAdapter wraps stuff in MvxListItemView. However, for the binding target, I don't see a reason why we couldn't just apply it on RadioGroup since it doesn't depend on anything in MvxRadioGroup directly. |
Cool. Let's take the binding discussion over to #1466. This probably isn't the only widget where we hit that problem. |
@Cheesebaron hey is this good? Did you look at the support lib version? |
I think this is good. Only thing was the MvxRadioGroup. I guess well take that in the issue you linked. So fix the merge conflict and we'll merge this. |
This weak event subscription handles the case where an object may be alive according to Xamarin but is dead according to the Java GC. Weak subscribe to Android View/Widget event sources This is more of a precaution than anything else.
…by the Android Runtime
9c5f376
to
10fde4b
Compare
Rebased onto develop. |
Yes this is fixed. You are still seeing the issue in the latest?
…On Dec 5, 2016 5:40 AM, "Artiom K" ***@***.***> wrote:
@kjeremy <https://github.com/kjeremy> could you clarify, is the #1405
<#1405> fixed by this PR? I
can see that the issue was closed but we still get this errors.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1446 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEIBRCP6UjaWFoRfdh0SlMs4SA75V_nuks5rE-o5gaJpZM4KMNAM>
.
|
Occasionally we can get in a state where an object has been garbage collected by the Android GC but not Mono. This is most common with
MvxRecyclerView
where we can't deterministically destroy the bindings.To protect against this we need to detect invalid Java Handles and skip setting binding values. Part of this change introduces a weak event subscription model that also takes this into account. We now weak subscribe to Android Views/Widgets in an attempt to reduce the refcount on the Mono side. The latter change is more of a precautionary measure but is part of the reason we're seeing: #1405
Fixes: #1402
This is the first part of a two part fix for:
#1405
#1444