I have a problem about memory with flutter app, when using compute, I put this line in the function parameter in compute:
var image = imglib.Image.fromBytes(
To try to reproduce with your sample, I had to convert from a ui.Image first:
Future _bytePng(ui.Image image) async {
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
Uint8List byteList = byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes);
return byteList;
}
The run a simplified version of your sample:
imglib.Image image2 = await compute(_getImage, [image1.width, image1.height, byteList]);
Future _getImage(List values) async {
var temp = imglib.Image.fromBytes(values[0], values[1], values[2], format: imglib.Format.bgra);
var rng = new Random().nextInt(50);
imglib.Image cropped = imglib.copyCrop(temp, 0, 0, temp.width - rng, temp.height - rng);
return cropped;
}
But I wasn't able to see the memory go out of control. So you probably have something else going on.