D
D
dailysse2017-09-25 19:46:30
Node.js
dailysse, 2017-09-25 19:46:30

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);

How to clear memory after creating buffers?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RidgeA, 2017-09-25
@RidgeA

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).

V
Vitaly, 2017-09-28
@vitali1995

All JS engines use the garbage collector. If memory management is critical for you, you can look at C++ frameworks such as Tufão

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question