sherpa-onnx icon indicating copy to clipboard operation
sherpa-onnx copied to clipboard

[Flutter] Hot release doesn't free up the RAM taken by the model

Open esuljic opened this issue 2 months ago • 2 comments

In the development, I start the Isolate.spawn with a kokoro-en-v0_19 model. After hot restarting the app, it doesn't free the memory used in the previous VM instance. It is reproducable in both Android and iOS for me. I am attaching memory charts of both platforms, and you can see the hot restart event clearly there. For every hot restart it increases by 800-900MBs, until crashed.

Image Image

esuljic avatar Sep 29 '25 11:09 esuljic

@dosu

csukuangfj avatar Sep 29 '25 12:09 csukuangfj

This looks like a native memory leak: Flutter hot restart resets the Dart VM but doesn't guarantee cleanup of native resources, especially those allocated by isolates or native libraries like sherpa-onnx. If the model or native resources aren't explicitly disposed before a hot restart, their memory can persist and accumulate with each restart.

Check if the plugin or your code provides a way to dispose or unload the model and native resources before a hot restart. Make sure isolates are properly terminated and any native cleanup methods are called. If no explicit disposal is available, this may be a limitation of the current integration between Flutter and the native library. Testing with a minimal example can help confirm if the leak is specific to sherpa-onnx or a general native resource management issue in Flutter.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar Sep 29 '25 12:09 dosubot[bot]