这是内存泄漏吗?
class Leaky { constructor(options) { process.on('message', function(msg) { this.do_something(msg) // ... }.bind(this)) } // ... }
当我打电话的时候 new Leaky() 引用通过处理程序绑定到实例。 process 不会被气相色谱分析所以我就泄露了 Leaky 例子
new Leaky()
process
Leaky
我怎样才能防止这种情况?我能想到的唯一解决办法就是 dispose 调用 process.off ,但我想避免。我看不到类似的东西 unref 或是身体虚弱 EventEmitter .
dispose
process.off
unref
EventEmitter