简体   繁体   English

setInterval处理程序是否被视为内存泄漏?

[英]Is setInterval handler considered a memory leak?

The javascript code: javascript代码:

function blah()
{
    var blahInterval = setInterval(function(){ 
        if( some_global_variable == 5 )
            clearInterval(blahInterval);
    }, 1000);
}

I have this code with multiple variants, and it is going to be called gazillion times in a NodeJS script. 我有多个变体的代码,在NodeJS脚本中将被称为千亿次。 Shall I delete blahInterval; 我应该delete blahInterval; after clearInterval ? clearInterval之后?

Is this a memory leak? 这是内存泄漏吗? Or the GC will clean it once setInerval function goes out of scope? 还是一旦setInerval函数超出范围,GC就会清理它?

The GC should clean it when it goes out of scope. 超出范围时,GC应该对其进行清洁。 As long as the if condition can be false to clear the interval. 只要if条件可以为false即可清除间隔。 I would not consider it a memory leak. 我不会认为这是内存泄漏。

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

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