tlrobinson / long-stack-traces

Long stacktraces for V8 implemented in user-land JavaScript. [UNMAINTAINED] Use https://github.com/mattinsler/longjohn instead

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Closures and some other objects seem to be leaking

twills opened this issue · comments

A very simple test program appears to illustrate this:

require('long-stack-traces');
require('v8-profiler');
var test = function()
{
console.log("in function");
setTimeout(test, 10);
}

test();

If I run this with node --debug and look at the heap in node-inspector, I see significant increases in closures and a few other object types over time. If I comment out require('long-stack-traces'), this behavior does not occur.

Technically it's not a leak because you're actually creating a very long chain of stack traces. We could add a limit to the length or something.

OK, yeah, I see what you're saying... But it does render long-stack-traces unusable in node programs which employ this sort of setTimeout pattern. Let's say an exception does occur at some point in my test function, after several intervals. Then I'd get a long stack trace like the following. I don't think all those repeated intermediate frames are useful anyway. So I wonder if it would be possible to detect repeated stack traces like this and compress them, including a message like "called 150 times" or whatever?

Uncaught ReferenceError: x is not defined
at Object. (/home/user/tim/test.js:7:3)

at Timer.callback (timers.js:62:39)

at Object.setTimeout
at Object.<anonymous> (/home/user/tim/test.js:9:2)
at Timer.callback (timers.js:62:39)

at Object.setTimeout
at Object.<anonymous> (/home/user/tim/test.js:9:2)
at Timer.callback (timers.js:62:39)

at Object.setTimeout
at Object.<anonymous> (/home/user/tim/test.js:9:2)
at Timer.callback (timers.js:62:39)

at Object.setTimeout
at Object.<anonymous> (/home/user/tim/test.js:9:2)
at Timer.callback (timers.js:62:39)

at Object.setTimeout
at Object.<anonymous> (/home/user/tim/test.js:9:2)
at Timer.callback (timers.js:62:39)

at Object.setTimeout
at Object.<anonymous> (/home/user/tim/test.js:9:2)
at Timer.callback (timers.js:62:39)

at Object.setTimeout
at Object.<anonymous> (/home/user/tim/test.js:9:2)
at Timer.callback (timers.js:62:39)

at Object.setTimeout
at Object.<anonymous> (/home/user/tim/test.js:9:2)
at Timer.callback (timers.js:62:39)

at Object.setTimeout
at /home/user/tim/test.js:9:2
at Object.<anonymous> (/home/user/tim/test.js:12:1)
at Module._compile (module.js:373:26)
at Object..js (module.js:379:10)
at Module.load (module.js:305:31)
at Function._load (module.js:271:10)
at Array.<anonymous> (module.js:392:10)
at EventEmitter._tickCallback (node.js:108:26)

Maybe. Could you switch to using setInterval instead?

Unfortunately that's not ideal for my application. I only want to trigger the next execution of the function after the previous execution has completed, so setting up repeated execution of the function on a regular interval via setInterval doesn't really work for me.

This is even more harsh in Node 0.6.7+... Node detects the memory leak and throws an exception.