Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
133 views
in Technique[技术] by (71.8m points)

Flutter: memory leak with isolate (compute)

I see memory leak every time I call compute() in my Flutter app, which is basically just a convenient way to spawn an isolate as far as I understand. My app memory footprint grows and never goes down after GC. I've reduced my code to just calling an empty function - and the issue is still reproducible:

  // run my _encodeJpeg in isolate
  await compute(_encodeJpeg, null);


  Future<void> _encodeJpeg(_JpegEncodeParams params) async {
    // I've made this function empty just to see if the memory leak is still reproducible - yes it is!
  }

Note that if I don't call compute() - there is no memory leak in my app. So it is definitely compute() that cause the issue.

Then I've created a new starter Flutter app (default one with button and counter) - and call compute() from that app the same way and it works fine! No memory leaks. Weird, right?!

There is something in my app that cause memory leak on compute(), while the app itself (if I don't call compute) doesn't have any memory leaks. I've created my app using some of the previous versions of Flutter, but now I compile it using the latest Flutter (see below).

Could there be something in my app that needs to be updated manually to make compute() work as expected?

UPDATE: I don't see this issue using library such as Computer (https://pub.dev/packages/computer):

final computer = Computer();
await computer.turnOn(workersCount: 1);
await computer.compute<void, _JpegEncodeParams>(_encodeTempJpeg, param: ...);
computer.turnOff();

flutter doctor:

[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.18363.1256], locale en-US)
? Flutter version 1.22.5 at C:sdkflutter
? Framework revision 7891006 (6 weeks ago), 2020-12-10 11:54:40 -0800
? Engine revision ae90085a84
? Dart version 2.10.4
question from:https://stackoverflow.com/questions/65844298/flutter-memory-leak-with-isolate-compute

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...