我对flutter应用程序的内存有问题,在使用计算时,我将这一行放在计算的函数参数中:
var image = imglib.Image.fromBytes(values[1].width, values[1].height, values[1].planes[0].bytes, format: imglib.Format.bgra);
Run Code Online (Sandbox Code Playgroud)
并以循环方式运行它,内存每次都会保持增长,然后内存不足,应用崩溃。
如果我没有那条线,则内存稳定在40mb。因此,我认为在计算中,在计算功能完成后并没有清除它。
有人有同样的问题吗?
编辑:
这就是我实现计算的方式:
image = await compute(getCropImage, [copyFaces, streamImg]);
Run Code Online (Sandbox Code Playgroud)
在getCropImage中:
Future<imglib.Image> getCropImage(List<dynamic> values) async {
var image = imglib.Image.fromBytes(values[1].width, values[1].height, values[1].planes[0].bytes, format: imglib.Format.bgra);
double topLeftX = values[0][0].boundingBox.topLeft.dx.round() -
(values[0][0].boundingBox.width * 0.2);
double topLeftY = values[0][0].boundingBox.topLeft.dy.round() -
(values[0][0].boundingBox.height * 0.2);
double width = values[0][0].boundingBox.width.round() +
(values[0][0].boundingBox.width * 0.4);
double height = values[0][0].boundingBox.height.round() +
(values[0][0].boundingBox.height * 0.4);
if (topLeftX <= 0) {
topLeftX = 25;
}
if (topLeftY <= 0) { …Run Code Online (Sandbox Code Playgroud) const shift = (0xFF << 24);
Future<Image> convertYUV420toImageColor(CameraImage image) async {
try {
final int width = image.width;
final int height = image.height;
final int uvRowStride = image.planes[1].bytesPerRow;
final int uvPixelStride = image.planes[1].bytesPerPixel;
print("uvRowStride: " + uvRowStride.toString());
print("uvPixelStride: " + uvPixelStride.toString());
// imgLib -> Image package from https://pub.dartlang.org/packages/image
var img = imglib.Image(width, height); // Create Image buffer
// Fill image buffer with plane[0] from YUV420_888
for(int x=0; x < width; x++) {
for(int y=0; y < height; y++) {
final …Run Code Online (Sandbox Code Playgroud) flutter ×2