[翻译]  How to destroy firebase ref in node

[CHINESE]  如何在节点中销毁firebase ref


If I do this in node:

如果我在节点中这样做:

console.log('1');
console.log('2');

outputs:

输出:

1
2

And the process ends.

这个过程结束了。

If I change it to this:

如果我改成它:

console.log('1');
var Firebase = require('firebase');
var ref = new Firebase('https://<some-base>.firebaseio.com/');
console.log('2');

outputs:

输出:

1
2

and the process continues.

并且该过程继续。

I believe that this is because ref is keeping the process alive. I know that I can use process.exit but I would prefer to not do that. I actually don't want the process to exit anyway, I just want to make sure that I don't have a memory leak issue where my firebase ref lasts forever. Is there any way to destroy a firebase reference once I'm done with it?

我相信这是因为ref使这个过程保持活力。我知道我可以使用process.exit,但我宁愿不这样做。我实际上不希望进程退出,我只是想确保我没有内存泄漏问题,我的firebase ref永远存在。一旦我完成它,有没有办法销毁firebase引用?

2 个解决方案

#1


7  

[Engineer at Firebase] Currently, instantiating the Firebase client with new Firebase(...) will create a long-lived persistent connection that keeps the Node.js process alive.

[Firebase工程师]目前,使用新的Firebase(...)实例化Firebase客户端将创建一个长期持久连接,使Node.js进程保持活动状态。

This is admittedly not ideal for a bunch of use cases, and we have some work to do here to ensure that the process exits cleanly and automatically when there are no outstanding Firebase listeners or pending writes to the server, but it's been medium / low priority. I'd expect a "fix" to be released by Q2 '15, hopefully Q1.

对于大量用例而言,这无疑是不理想的,我们还有一些工作要做,以确保在没有未完成的Firebase侦听器或挂起的写入服务器时,进程干净自动地退出,但它是中/低优先级。我希望在2015年第二季度之前发布“修复”,希望是Q1。

#2


0  

One workaround I found when using tape was to call test.onFinish(() => process.exit()); at the end. It's not ideal but it seems to get the job done running it both directly and with a test runner.

我在使用磁带时发现的一个解决方法是调用test.onFinish(()=> process.exit());最后。它并不理想,但它似乎完成了直接运行并与测试运行器一起运行的工作。

Example:

例:

const test = require('tape');

test('Some test', (t) => {
  // test code
});

test('Another test', (t) => {
  // test code
});

test.onFinish(() => process.exit());

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号