AndreasMadsen / trace

Creates super long stack traces
https://trace.js.org
MIT License
194 stars 18 forks source link

Memory leak of sorts #35

Open abrenneke opened 6 years ago

abrenneke commented 6 years ago

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.

AndreasMadsen commented 6 years ago

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

abrenneke commented 6 years ago

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

foray1010 commented 6 years ago

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

jbunton-atlassian commented 6 years ago

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

Somebi commented 4 years ago

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