-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix various issues in object dispose methods. #6467
Conversation
@@ -83,6 +83,14 @@ protected override void Dispose(bool disposing) | |||
|
|||
if (disposing) | |||
{ | |||
if (Element != null) | |||
{ | |||
Element.PropertyChanged -= OnElementPropertyChanged; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I very much like this pattern of unsubscribing all the event handlers before unhooking other stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fix in ItemsViewRenderer might not quite be right. Other than that, this looks great!
Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs
Outdated
Show resolved
Hide resolved
I have removed the collection view part, moved to PR 6525. |
…dispose ShellSectionRenderer - Call base.Destroy last + Remove and destroy _scrollview
Rebased to fix conflict (bis). |
@kvpt build seems to fail on:
|
Thanks for the report, I surely fail the last rebase. |
Has it been included in the latest 4.1 release? |
No, this was included on the master branch, so it will be included in the 4.2 branch. |
Has it been included in the latest 4.2.0.618605-pre2? Android continue giving this error on the FastRenderers for ImageRenderer and LabelRenderer. AppCenter Logs: Label log: TextView.set_TextFormatted (Java.Lang.ICharSequence value) Image log: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer'. Java.Interop |
@JosueDM94 It is normally included since the 4.2.0-pre1.2 version. Have you noticed a reduction in the number of this type of crashs with since this version or not ? This PR will normally reduce the probability that this happen but it is in theory possible that dispose and event execute in parallel. On some heavy load or particular scenario it seems to be happening. From the StackTrace it's very clear that the issue is on this line.
Element.Text return the text but when Android side try to affect it the Control.Text fail because the Control has been disposed. We have two ways to fix this :
|
I tested 4.2.0.618605-pre2, and I was getting the same number of this suddenly crash on the app. This is the whole scenario, I have a MasterDetailPage, and on the master page, I have a listview with a view cell that contains a label and image, those elements had attached triggers to change the color from the image and text of the option selected. I applied a bindable effect to the image to change the tint color from the image source and the label I'm using the text color property, at least for the effect, I could control the exception with a try-catch with ObjectDisposedException. |
For the ImageRenderer I have no idea because I don't find method ClearColorFilter in the code for the ImageRenderer, the only place where this method seem to be used is in the Switch renderer and SwitchCell renderer, strange. |
Label and Image trigger where change the text and image color from the menu selection.
This is the effect code for the tint color to apply to the Image control
|
We have two separates issues here :
|
Context
fixes #5611
I notice in my apps a lot of these exceptions on Android, very hard (or even impossible) to reproduce.
I fixed some of them in #4707, #4955, #4974 but I continue to have a certain amount of them.
And there are plenty of them on the Xamarin Forum or in the issues list of this repository (and the previous on bugzilla).
When fixing the dispose method of the TabbedPageRenderer in #4974, I notice that most dispose methods in the Android backend have also issues.
Description of Change
The complete modifications list is :
AppCompat/CarouselPageRenderer
AppCompat/FormsAppCompatActivity
AppCompat/ImageButtonRenderer
AppCompat/MasterDetailPageRenderer
AppCompat/NavigationPageRenderer
AppCompat/Platform
AppCompat/ShellFragmentContainer
AppCompat/TabbedPageRenderer
FastRenderers/AutomationPropertiesProvider
FastRenderers/ButtonRenderer
FastRenderers/FrameRenderer
FastRenderers/ImageRenderer
FastRenderers/LabelRenderer
FastRenderers/VisualElementRenderer
ShellSectionRenderer
VisualElementPackager
VisualElementRenderer
Issues Resolved
A lot of random and hard to reproduce issues.
API Changes
None
Platforms Affected
Behavioral/Visual Changes
None
Before/After Screenshots
Not applicable
Testing Procedure
Run all of the solution tests cases, there must be no regression.
PR Checklist
Additionnal words
These kind of issues are, in addition, masked by the contructor (IntPtr/JniHandleOwnership), which makes the leaks very difficult to see. I dont remove them in this PR but I think they are an anti pattern which hide the leak instead of fix it.
To conclude, the stability being the most critical factor, please prioritize this PR.
I'm sure I have missed some issues, so more pair of eyes are welcome.