memory leak #25644
Comments
TL;DR I don't think your sample code shows a memory leak. I would say that this code doesn't let V8's garbage collector run often enough, and that it shows Now for a longer version. Memory leaks in node are very often quite complex to investigate because it generally depends on how V8's garbage collector can manage to run. In your example, allocating memory by running Now another data point that is more interesting to have is What's interesting is that the garbage collector's behavior can depend on subtle things. For instance with your sample code, building node with or without support for snapshot changes how much and how often the garbage collector can run. I suspect this is because running a script in a new context is faster with snapshots, and leaves some time for the garbage collector to run, but that's a wild guess. Official releases of node are built without snapshots, and thus seem to struggle more to reclaim objects from the heap with your sample code. If you build the source yourself with To get a behavior that is closer to what we intuitively think is better (having the heap not grow between iterations of a tight loop), it is possible to force V8's garbage collector to run by calling Doing that with your sample code, both
and running your sample code + a call to To conclude, I will close this issue as I don't think it shows any issue with node itself, but feel free to comment further if you have any question. The need for the patch I just mentioned above to make |
Hi. Thank you for your detailed answer. I try run it with setInterval and also use global.gc(), but still I watched a memory leak. |
Hi. I watch the memory is up to much.
node: 0.12.6
example app.js:
var vm = require("vm");
var result = false;
while (true){
result = vm.runInNewContext("1==1",{});
console.log(result);
console.log(parseInt(process.memoryUsage().heapTotal / 1024 / 1024));
}
For each iteration memory increase by 1Mb.
I created a issue report on http://code.google.com/p/v8/issues/detail?id=4281, but I was sent here :)
The text was updated successfully, but these errors were encountered: