我对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) 我的应用程序使用 grpc 将图像从客户端发送到服务器,但我无法捕捉到该错误,这是我的代码:
var response;
try {
response = await dataService.sendFace(
listImageToListFaceRecImage(
dataImages, dataTrackID, dataRect, dataLandMark),
dataDeviceID,
dataDoorID);
} catch(e) {
print('Caught error: $e');
}
response.first.then((value) {
isSending = false;
print("receive");
print(value.result);
if (value.result.isNotEmpty) {
Map<String, dynamic> result =
(jsonDecode(value.result) as List<dynamic>)[0];
String personCode = result['person_code'];
replyTo.send([personCode, capturedFaceImage]);
}
});
Run Code Online (Sandbox Code Playgroud)
我想要的结果是:
捕获错误://此处出错
但它显示了这个错误,我不知道为什么它无法捕获:
gRPC 错误(14,连接错误:SocketException:连接失败(操作系统错误:网络无法访问,errno = 101),地址 = 172.16.0.39,端口 = 4001)
我正在尝试使用 protoc-plugin 将 proto 文件生成为 dart 文件,请遵循此说明https://grpc.io/docs/quickstart/dart/但是当我运行此命令行时
protoc --dart_out=grpc:lib/proto --plugin=protoc-gen-dart=C:/src/flutter/flutter/.pub-cache/bin/protoc-gen-dart.bat -Iprotobuf protobuf/utils.proto
Run Code Online (Sandbox Code Playgroud)
它显示了这个错误:
'dart' is not recognized as an internal or external command,
operable program or batch file.
'pub' is not recognized as an internal or external command,
operable program or batch file.
--dart_out: protoc-gen-dart: Plugin failed with status code 1.
Run Code Online (Sandbox Code Playgroud)
我已经在我的 Android Studio 中安装了 dart 作为插件。我是否必须安装 dart SDK 并将其添加到环境变量路径才能工作?
更新
在我安装 dart sdk 并重新启动我的电脑后它就起作用了。
我的应用程序使用相机和人脸检测连续检查人脸并将图像人脸发送到服务器以检查并接收显示结果的响应,因此它有很多工作要做。
我的应用程序必须 24/24 全天候运行,但大约 30 分钟后,它开始滞后于相机预览并崩溃。我检查了内存视图,它一次又一次地增加,所以我认为应用程序由于内存不足而崩溃。
我曾尝试使用 Isolate 但感觉它不起作用。任何人都可以帮助我吗?
我想缓存我在 flutter webview 中显示的网页,以便提高我的性能,无需重新加载页面。那可用吗?我可以实施吗?
我想将相机图像从 Flutter 中相机插件的函数 startImageStream() 转换为 Image 以裁剪该图像,但我只找到了转换为 FirebaseVisionImage 的方法。
我正在制作一个经常使用异步的 Flutter 应用程序,但它不像我理解的那样工作。所以我对 dart 中的 async 和 await 有一些疑问。下面是一个例子:
Future<int> someFunction() async {
int count = 0;
for (int i=0; i< 1000000000;i ++) {
count+= i;
}
print("done");
return count;
}
Future<void> test2() async {
print("begin");
var a = await someFunction();
print('end');
}
void _incrementCounter() {
print("above");
test2();
print("below");
}
Run Code Online (Sandbox Code Playgroud)
test2() 函数需要很多时间才能完成。对?所以我想要的是当 test2 保持他的工作运行直到完成时,一切都会继续运行而不是等待 test2()。
当我运行函数 _incrementCounter() 时,它显示结果:
以上开始完成以下结束
问题是它没有立即显示“下方”,而是等到 someFunction() 完成。
这是我想要的结果:
上面开始下面完成结束