-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
fix: Close barcode scanner and free it's resources #1181
Conversation
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.
You close the barcodeScanner
but you never reopen it...
I guess the open/close behavior should be somehow similar to the controller's.
Added documentation @monsieurtanuki |
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.
@M123-dev You're missing the point: how do you expect the barcodeScanner
to work after being closed? This stop
method is called on an onPause
callback, with a corresponding onResume
callback. If onResume
is called after onPause
, the barcodeScanner
will be closed.
No I understand what you mean @monsieurtanuki, its just that there is no way to manually start the scanner. ML Kit just has three public methods: https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/BarcodeScanner?hl=en The scanner is "started" when giving it it's first image |
Then your solution cannot work. After you close the barcodeScanner with |
I think we are talking past one another here @monsieurtanuki The lifecycle looks like it:
There isn't even a public start method from ml kit, it's all done internally On android it worked fine without closing the scanner but maybe this differs from android to iOS maybe they have a check that the scanner can't handle a new pic if the last one is still in there without responsing or so, honestly idk but it's worth trying |
@M123-dev If you want to destroy the barcode scanner, I guess the correct syntax would be: await barcodeScanner?.close();
barcodeScanner = null; Then come my previous remarks about the difference between In this current PR, assuming that the mere presence of the barcode scanner is a nuisance, I suggest that you just create a new |
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 would be cleaner with no default value at construction time:
BarcodeScanner? barcodeScanner;
instead of
BarcodeScanner? barcodeScanner = GoogleMlKit.vision.barcodeScanner();
But that's ok too I guess.
…om/openfoodfacts/smooth-app into ml-kit-ios-second-scan-attempt-fix
I wondered why it would fail but only on the second attempt, maybe this fixes it, even if not its good for freeing unused resources
cc: @cli1005