gpt4 book ai didi

memory-leaks - Dart Websocket内存泄漏

转载 作者:行者123 更新时间:2023-12-03 03:43:37 24 4
gpt4 key购买 nike

我正在使用websockets接收 Protocol Buffer 并遇到内存泄漏。无论传入缓冲区的大小和频率如何,都会发生此泄漏。

protobuf被作为Blob接收,但作为arrayBuffer接收时存在相同的泄漏。目前,我实现的只是一个数据包处理程序,该处理程序将Blob设置为null以尝试调用垃圾回收。

我的收听电话:ws.onMessage.listen(handlePacket);
我的事件处理程序:void handlePacket(message) { message = null; }
我不完全了解websocket中的messageEvents流是否是不使已处理事件出队的队列,但是看来分配给传入事件的所有内存都无法被垃圾回收。感谢所有帮助。

编辑
客户端代码:

  void _openSocket() {
if (ws == null) {
ws = new WebSocket('ws://localhost:8080/api/ws/open');
// ws.binaryType = "arraybuffer";
}
}

void _closeSocket() {
if (ws != null) {
ws.close();
print("socket closed");
ws = null;
}
}

void _openStream (String fieldName, [_]) {
//Check if we need to open the socket
_openSocket();
//Request the proper data
Map ask = {"Request": "Stream", "Field": fieldName};
if (ws.readyState == 0){
ws.onOpen.listen((_) {
ws.send(JSON.encode(ask));
});
} else {
ws.send(JSON.encode(ask));
}

activeQuantities++;
if (activeQuantities == 1) {
_listen();
}
}

// Receive data from the socket
_listen() {
ws.onError.listen((_){
print("Error");
});
ws.onClose.listen((_){
print("Close");
});
ws.onMessage.listen(handlePacket);
}

void handlePacket(message) {
message = null;
}

最佳答案

看起来Dartium可能会泄漏内存,但是使用Dart2js并在Chrome中运行时,尽管显示出与Dartium相同的症状,但确实设法达到了GC。 https://github.com/dart-lang/sdk/issues/26660

关于memory-leaks - Dart Websocket内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37666093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com