-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in Node.js #1417
Comments
from language (JS / C++) perspective, the locals remain locals to a method, so there is no semantics that allow it. from system's perspective, a hack is possible: callee being C++, it could unwind a couple of stack frames, locate the caller's function object and modify the locals before it returns - but it is a pure hack. from v8's perspective, I don't know, but probably @nodejs/v8 would. |
There is no easy way to do this. Locals that are not bound are stack-allocated. You could use the inspector to modify it, but the inspector doesn't support modifying locals if the frame is of an optimized function. Could you describe your use case? Maybe there is a better way? |
Thanks My use case is like this: Suppose I have following script for(;;){
new class{};
// Optional (requires --expose-gc flag)
gc();
} I run it and then monitor process memory allocations using some memory monitor. I see that memory is growing and after some time (leave it for several hours) it crashes the Node.js process. I googled a bit and still not sure why it happens. This is simplified example, but my real app should run in a synchronous loop and synchronously communicate with other apps, but this crashing behavior is problematic. So I tried to create a workaround: a C++ module that cleans up parent scope stack and deallocate everything that gc is unable to deallocate.
That would be great, and also I would like to know why this code causes node.js to crash, I mean what is preventing the gc from doing what it is supposed to do? I also noticed if the infinite |
I see. So you are actually dealing with a memory leak. Do you still observe the same memory increase if you refactor the loop body into a new function, and call it from the for-loop? Also make sure to use let-declarations instead of var-declarations. |
With this code memory increases at speed ~24KB/s. 'use strict';
let func = () => {
new class{};
gc(); // Just to reduce memory fluctuating
};
for(;;){
func();
} I'm starting to believe that this is some sort of v8 (or node) bug. I run this code on Node.js v4.0.0 and memory doesn't increase. Memory increases starting from version v6.0.0 I think. And even if using Tested on gecko repl and memory is not increasing at all. What may be the problem here, if it is not a v8 regression (especially according to the fact that this doesn't leak in node v4.0.0)? |
Indeed seems like a V8 bug. I filed an issue: https://bugs.chromium.org/p/v8/issues/detail?id=8037 |
Actually, I can't reproduce this:
|
Hm... What now? The crash is real in the sense that the code breaks Node.js process after some time. How can I help reproduce this? Should I file an issue at Node.js main repo? In meanwhile I ran longer test using Do I need to provide Node.js process full memory dump (obtained using task manager), would it help? Since the issue (?) is introduced in Node.js v6.0.0, can I help somehow confirm it or bisect to specified commit in order to reveal what may cause it? Thanks for cooperation so far. |
At least with V8's own shell, I wasn't able to reproduce a memory growth with the newest V8 version. I can however reproduce very slow growth in Node.js itself. Seems like a bug in Node. I filed an issue against Node.js. |
Thanks. I'm closing this. |
XP, 7, 8, 8.1, 10 all x64myModule
is a C++ module that is a function, which should be able to access local scope of the function from where it is called (likeeval
) and modify value ofa
(set it to7
) and also create local (not global) variableb
with value8
. How to do that?Calling
myModule
should be equivalent of callingeval('a=7;var b=8')
. Basically, is there a way to access parent scope variable list and modify it directly from v8?Many thx.
The text was updated successfully, but these errors were encountered: