Skip to content
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

Kill isolate when camera is disposed #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

batkhishign55
Copy link

@batkhishign55 batkhishign55 commented Jan 14, 2022

Hi,

I found a problem while trying to implement the project in a different flutter app. When you close the camera and open again, there is a leftover process. If you do it over and over again, it will eventually fill up memory.

The problem is when camera is disposed, there's still an active isolate thread in the background. Therefore a simple fix was to kill the isolate on camera disposal.

@espbee
Copy link

espbee commented Jan 22, 2022

@batkhishign55 I found that I had to do this as well. Quick side question-- have you found any memory leak issues on ios ? If you look at the runtime memory usage in XCode? I've been finding that when I dispose the Classifier / close the interpreter -- even in a test app with no camera view at all, no isolates, no actual inference -- the model doesn't seem to deallocate. Rather, the next time I run it, the memory usage drives higher, and so on, until eventually the app crashes.

Wondering if you've by any chance found anything similar? Or are your Classifier / interpreter / model clearing out totally when you close / dispose?

@batkhishign55
Copy link
Author

batkhishign55 commented Jan 24, 2022

@espbee haven't tried it on ios because I don't have macos device yet. Will definitely look into it when I get a macbook in the future. If you find a solution, please share it with us.

@espbee
Copy link

espbee commented Jan 24, 2022

@batkhishign55 i'm still not totally confident but the solution seems to be loading the model from file rather than asset-- if anyone is loading from asset. he's got a little block of commented description in the docs about saving the asset to a temp dir and loading the file from there-- it's how you'd do it anywhere in flutter. that approach seems to let the memory release, whereas when i loaded from asset directly, it did not.

For what it's worth,I'm not running the example app directly, more took inspiration about dealing with camera frames, and combined it with a slightly different isolate approach-- which comprises a part of the app I'm using it in.

However, I did test this memory issue in the basic Flutter Counter App and it happened there as well, just the same, using the stock SSD model that comes with this example app: open interpreter / close -> no release.

This is on XCode 13 or 12.5.

Anyway if anyone finds this and encounters the same, I can only suggest looking into the File rather than direct Asset model loading approach to initializing your interpreter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants