Answer the question
In order to leave comments, you need to log in
How to clear memory?
Good day.
var y = [];
let a = setInterval(() => {
let b = 176400*10 / 1024 / 1024 / 1024;
y.push(Buffer.allocUnsafe(176400*10).fill('a'));
if (y.length>=1000) {
clearInterval(a);
y.forEach((value, key) => {
delete y[key];
});
y = [];
}
}, 3);
Answer the question
In order to leave comments, you need to log in
Memory cleanup should be handled by the GC.
In the above example, the memory cleanup occurs after `delete y[key]` (it's impossible to say exactly when this happens - this is a property of the GC).
There is a discussion of this issue here https://github.com/nodejs/node-v0.x-archive/issues/2995 and a link to a module for clearing memory from buffers, but IMHO, if there is a need for such a module, then something went wrong architecturally. It is necessary to optimize the work with memory, or, if it is not possible, increase the limit of allocated memory (if, of course, the system allows).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question