seeking help from a nodejs guru there using promises. I have the following test program in which I call the async "q" function, which simply throws an exception. This program runs pretty fast in memory; but the leak disappears if you uncomment the .done () call.
Why does a leak occur when a promise is not broken (i.e., a call to done ())? I tried to execute the documentation , but do not understand the understanding of the done () method. Thanks in advance for your help!
Here is my code:
(function() { var MAX_ITER_COUNT, Q, iterCount, maxMem, noop, qDoit, test; Q = require("q"); iterCount = 0; MAX_ITER_COUNT = 10 * 1000; maxMem = 0; noop = function() {}; qDoit = function() { var currentMem; currentMem = Math.round(process.memoryUsage().heapUsed / 1024 / 1024); if (currentMem > maxMem) { maxMem = currentMem; } console.log("" + iterCount + " - memory is: " + currentMem + "/" + maxMem + " MB"); return Q(10).then(function() { throw new Error("X"); }); }; test = function() { if (iterCount++ > MAX_ITER_COUNT) { console.log("DONE"); return; }
source share