trace icon indicating copy to clipboard operation
trace copied to clipboard

Memory leak of sorts

Open abrenneke opened this issue 7 years ago • 5 comments

Hello, infinitely recursing setTimeout calls will increase the memory usage forever.

Reproduction code: (node 8.9.1)

require('trace');
const memwatch = require('memwatch-ng');

memwatch.on('leak', info => {
    console.log('Memory leak detected.');
    console.log(info);
});

function loop (func) {
    const execute = () => {
        func().then(() => {
            setTimeout(execute, 0);
        });
    };
    execute();
}

console.log(`Stack trace limit is: ${Error.stackTraceLimit}`);

loop(async () => {
    await new Promise(resolve => setTimeout(resolve, 0));
});

I don't suppose there's a way for trace to limit its memory usage? I understand that I'm essentially creating an infinitely long stack trace, but this code does work without trace enabled.

abrenneke avatar Nov 16 '17 21:11 abrenneke

Unless Error.stackTraceLimit = Infinity it should clean up appropiately.

AndreasMadsen avatar Nov 16 '17 22:11 AndreasMadsen

You can try the above code, it leaks for me. Error.stackTraceLimit = 10, the default

abrenneke avatar Nov 16 '17 23:11 abrenneke

trace + clarify triggers memory leaks on my application too as following graph shows:

screen shot 2018-01-31 at 2 24 01 pm

23 Jan is the day I apply trace with clarify --stack_trace_limit=100 -r trace -r clarify, the app keeps using too much memory and kill itself

foray1010 avatar Jan 31 '18 06:01 foray1010

@foray1010 I've fixed that memory leak in PR #40

jbunton-atlassian avatar Mar 05 '18 22:03 jbunton-atlassian

Still leaking, because this PR wasn't merged. This project seems to be dead.

Somebi avatar Feb 13 '20 15:02 Somebi