Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Fix crash when repeating detection #872

Merged
merged 5 commits into from
Nov 13, 2018

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Oct 26, 2018

If you attempt to use a Detector multiple times on Android without calling detector.close() eventually the app will crash. This happens because a new detector is instantiated for each detectInImage is called. I'm assuming the crash is from running out of memory (I get a seg fault error) because each detector loads a hefty model.

iOS version doesn't have a close method, so I'm assuming it handles it's models differently.

My solution for this problem keeps one instance in memory to reuse. However, if the user wants to create a detector with different options, I close the previous instance and instantiate a new detector.

The other option would be to give each instantiated detector a handle, but closing and instantiating a new one doesn't take very long if there is a use case where multiple detectors are needed.

@Override
public void handleDetection(
FirebaseVisionImage image, Map<String, Object> options, final MethodChannel.Result result) {

FirebaseVisionBarcodeDetector detector =
FirebaseVision.getInstance().getVisionBarcodeDetector(parseOptions(options));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here a new instance is created without calling close() each time.

@kroikie kroikie merged commit d451cac into flutter:master Nov 13, 2018
@bparrishMines bparrishMines deleted the multi_detector branch November 13, 2018 23:34
andreidiaconu pushed a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
* Fix crash when using multiple queries
andreidiaconu added a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
* Fix crash when using multiple queries
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants