-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[camera_android_camerax] Fixes premature garbage collection of native objects when app is under memory pressure #9287
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
base: main
Are you sure you want to change the base?
Conversation
@@ -60,7 +60,7 @@ android { | |||
lintOptions { | |||
checkAllWarnings true | |||
warningsAsErrors true | |||
disable 'AndroidGradlePluginVersion', 'GradleDependency', 'InvalidPackage', 'NewerVersionAvailable' | |||
disable 'AndroidGradlePluginVersion', 'GradleDependency', 'InvalidPackage', 'NewerVersionAvailable', 'UnsafeOptInUsageError' |
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.
In #8618, I manually added this to the generated pigeon file CameraXLibrary.g.kt
. To prevent the need to manually change generated code, I moved the disable here.
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.
Working on another camera PR (#9264) and I created a baseline lint file for that same UnsafeOptInUsageError
lint. I think that might be better just in case the lint is valid for non-generated files, but let me know what you think!
If you agree and these other lints are from CameraXLibrary.g.kt
, maybe we should remove them and just regenerate the baseline file.
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'll wait for #9264 to land and then regen the baseline file for this PR
@@ -60,7 +60,7 @@ android { | |||
lintOptions { | |||
checkAllWarnings true | |||
warningsAsErrors true | |||
disable 'AndroidGradlePluginVersion', 'GradleDependency', 'InvalidPackage', 'NewerVersionAvailable' | |||
disable 'AndroidGradlePluginVersion', 'GradleDependency', 'InvalidPackage', 'NewerVersionAvailable', 'UnsafeOptInUsageError' |
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.
Working on another camera PR (#9264) and I created a baseline lint file for that same UnsafeOptInUsageError
lint. I think that might be better just in case the lint is valid for non-generated files, but let me know what you think!
If you agree and these other lints are from CameraXLibrary.g.kt
, maybe we should remove them and just regenerate the baseline file.
@@ -31,7 +31,7 @@ dev_dependencies: | |||
sdk: flutter | |||
leak_tracker_flutter_testing: any | |||
mockito: ^5.4.4 | |||
pigeon: ^25.3.1 | |||
pigeon: ^25.3.2 |
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.
Just to clarify: this is a guess at the fix for flutter/flutter#152763 or have you determined this is the cause?
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.
It is a guess, but a very educated guess.
I haven't been able to reproduce the exact error from the camerax_issue, but I have been able to reproduce the issues from flutter/flutter#168531 and flutter/flutter#168306 on iOS. Both of these are similar to the camerax_issue because they are NullPointerException
s caused by an instance that originates from the native side (e.g. ImageProxy
). Both of these were solved by bumping pigeon
to 25.3.2
.
I think it is harder to reproduce the error on Android because garbage collection for Java is nondeterministic and it requires the ImageProxy
to be garbage collected within a small time frame. But I did use a few debug logs to verify that the scenario described here does occur within the plugin. And that this change most likely prevents it. Although the scenario is pretty rare, so its not impossible that I was just lucky.
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.
Ah gotcha makes sense! SGTM :)
Note: Waiting on #9264 to land and to regenerate baseline file with.
This bumps
pigeon
to25.3.2
and regenerates the code to fix a bug where native objects were getting garbage collected prematurely. See flutter/flutter#168531Fixes flutter/flutter#152763
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3