简体   繁体   English

使用Socket.io发射传输数据后,如何释放内存中的数据?

[英]After transfering data using Socket.io emit, how could I release the data in memory?

For some reason, after using socket.emit(), the data is still in memory, according to Chrome's dev tool. 根据Chrome的开发工具,由于某种原因,在使用socket.emit()之后,数据仍在内存中。 Since I have to use this line of code for many times, the memory usage keep raising. 由于我不得不多次使用这一行代码,因此内存使用量不断提高。 My JS code on client : 我在客户端的JS代码:

socket.emit('upload',{data: a_very_long_string});

Local variable (declare with var ) in JS is garbage collected automatically when the function return. 当函数返回时,JS中的局部变量(用var声明)被自动垃圾收集。 And if it was a global variable, you can always release it by delete . 如果它是一个全局变量,则始终可以通过delete释放它。 So I guess in your case, it is because some global variable is not released after emit() . 所以我想在您的情况下,这是因为某些全局变量没有在emit()之后emit()

I found this post talking about memory leak in Socket.IO, which could be helpful in your case. 我发现这篇文章谈论Socket.IO中的内存泄漏,这可能对您有帮助。 http://jpallen.net/2013/03/08/tracking-down-a-memory-leak-in-node-js-and-socket-io/ http://jpallen.net/2013/03/08/tracking-down-a-memory-leak-in-node-js-and-socket-io/

About releasing variables, you can refer to this question: Memory release from local variable in JavaScript . 关于释放变量,您可以参考以下问题: JavaScript中从局部变量释放内存

That is a problem with socket.io. 那是socket.io的问题。 It is because of memory leak in websocket server. 这是因为Websocket服务器中的内存泄漏。

See the solution posted here : 请参阅此处发布的解决方案:

  1. http://jpallen.net/2013/03/08/tracking-down-a-memory-leak-in-node-js-and-socket-io/ http://jpallen.net/2013/03/08/tracking-down-a-memory-leak-in-node-js-and-socket-io/
  2. https://github.com/LearnBoost/socket.io/issues/1015 https://github.com/LearnBoost/socket.io/issues/1015

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM