-
Notifications
You must be signed in to change notification settings - Fork 464
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. ArrayBuffer finalizeCallback never called #917
Comments
Are you sure the GC is running and freeing the objects? There is no guarantee that the gc will run unless is needs memory. It's a classic problem that if you use lots of C++ memory tied to a objects without using a lot of memory on the heap (ie JS objects not counting the C++ memory) then the gc never needs to run and the C++ memory does not get freed. You can try to use: inline int64_t MemoryManagement::AdjustExternalMemory(Env env, int64_t change_in_bytes) {
int64_t result;
napi_status status = napi_adjust_external_memory(env, change_in_bytes, &result);
NAPI_THROW_IF_FAILED(env, status, 0);
return result;
} to let the gc know that objects are holding a lot of external memory alive. You need to adjust upwards when you crate the buffer and then adjust downwards in the cleanupHook. |
Adjusting the external memory doesn't seem to help. I added the following to GetDataWrapper():
And the following to cleanupHook():
|
Is the memory you are allocating just 6 bytes long? Do you have files for a full recreate that we can just run to look at the behaviour? |
@mhdawson I think the reason why it's not finalizing is that the Node-API finalizer attempts to call the user's finalizer via |
The sequence is this: |
nodejs/node@3ca0df2 introduces the |
@mhdawson looks like the reason @addaleax added the |
Can you confirm that changing while (true) {
// Get more data
var mydata = GetData();
console.log(mydata);
} to
Resolves the problem. If so that would confirm what @gabrielschulhof mentions as potentially contributing to what you are seeing. |
I would consider this expected behavior then. Switching to |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
I'm running into massive memory leaks when passing an array buffer from c++ to js.
The callback given to the ArrayBuffer only gets called on program close, and not when js no-longer references the data.
For a long running program, this doesn't really work.
test.js:
Relevant parts of c++
The text was updated successfully, but these errors were encountered: