flutter_tflite
flutter_tflite copied to clipboard
Memory leaks
I'm trying to use the example project. When I use different models I see that memory is not being release after close() method is called (iOS 14). If I use my custom model (64 MB) app gets crashed after 2 runs on device because it out of memory. Does anyone have any idea how to fix it?
I think the issue is that interpreter.release() is not being called causing the memory to be allocated https://github.com/shaqian/flutter_tflite/blob/ce8075a391e02e0cc0bc6c2db950aa961a17d745/ios/Classes/TflitePlugin.mm#L1488
This change seems to work.
void close() {
#ifdef TFLITE2
+ if (interpreter != nullptr) {
+ TfLiteInterpreterDelete(interpreter);
+ }
interpreter = nullptr;
if (delegate != nullptr)
TFLGpuDelegateDelete(delegate);
delegate = nullptr;
However, in ios, there is a memory leak even in inference processing. Does anyone know any solution tips?
@yokoi-engineering can you point me where the memory leak is occurring i can take a look
interpreter
and options (in loadModel func)
and model
and 'delegate'
Now that I'm away from work, I'll paste the code.
void close() {
#ifdef TFLITE2
if (interpreter != nullptr) {
TfLiteInterpreterDelete(interpreter);
}
interpreter = nullptr;
if (options != nullptr) {
TfLiteInterpreterOptionsDelete(options);
}
options = nullptr;
if (model != nullptr) {
TfLiteModelDelete(model);
}
model = nullptr;
if (delegate != nullptr) {
TFLGpuDelegateDelete(delegate);
}
delegate = nullptr;
#else
interpreter.release();
interpreter = NULL;
#endif
model = NULL;
labels.clear();
}
options
move to member.