-
Notifications
You must be signed in to change notification settings - Fork 461
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
Object wrap has a memory leak bug? #1213
Comments
Hi @ammarfaizi2 , We discussed this on today's Node API meeting. This is a similar issue as found on #1140 . We are waiting on some PRs in node core (nodejs/node#42651, nodejs/node#44141) that we believe should resolve this problem. As discussed in the above linked issue, if you make your code asynchronous, the finalizers will have a opportunity to run in between your JavaScript execution. |
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. |
Dropping a comment, just to avoid closing. |
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. |
Dropping a comment, just to avoid closing. |
I have come here with exactly the same issue. I understand the issues in allowing finalisers to run whenever, but if one did not give access to the
|
@audetto access to the napi_env is needed for things like |
I see, I did not realise there are 3 cases: run normal js, context case and no js at all. |
I have enabled |
which feature did you enable through |
@Apidcloud , you should just be be able to define Let us know if you have any other questions/problems. Thanks, Kevin |
Things have changed since November 2023. When I define If I dont define it, the gc still runs only at the end. I cannot see Is |
This is the error
|
The offending line does this
the same code compiles without |
There was a recent addition covered under NAPI_EXPERIMENTAL to help people avoid calling into JavaScript when they should not be in finalizers. See - nodejs/node#50060. The "compiles with NAPI_EXPERIMENTAL.. but does not behave correctly" likely means that the code was making calls to JS where it should not be and therefore "did not behave correctly" You can opt out of this change with NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT if you use NAPI_EXPERIMENTAL which will likely let you compile again, but you will also be back to "it not behaving correctly". Your best bet is to update so that you can compile with the change, that process should also hopefully help narrow down in the code what was causing the "did not behave correctly" |
Yes, this is exactly what I want to use. My finalisers just call
"correctly" here means that the finaliser is called immediately (i.e. synchronous), as soon as gc runs.
If I define
"update" what exactly? Could you please show me an example when I can call this Line 1416 in 23bb42b
It might sound unrelated to the original problem, but it is the first compiler error I have when I enable |
Moreover, since I cannot find any match for But I hope to be completely wrong. |
Look at that:
But here Line 68 in 23bb42b
we still pass a So this only works if So it still dont think |
Hi @audetto , This came up in the 10 May Node-API meeting. The current WIP linked above fixes compilation in experimental mode by wrapping finalizers in a We are actively discussing the required node-addon-api changes in order to support the In the meantime, you can use the underlying Node-API call to |
It looks to me that this extensions requires C++17, maybe it should be checked and an error returned otherwise. |
I solved compilation problems, but I am back in a situation where the finaliser is not called synchronously. I define How do I tell |
Finally, I got it to work. My finalisers were using If I understand correctly, a |
Closing this issue as solved by #1514 |
I have got several memory leak issues with this addon library.
I thought it was me who wrote the code wrong. But when I am trying
to run this example, it has the same memory leak too:
https://github.com/nodejs/node-addon-api/blob/main/doc/object_wrap.md
Run the JavaScript code in a
while (1)
loop will reveal the memoryleak issue.
What is going wrong with this?
C++ code
JavaScript code
The text was updated successfully, but these errors were encountered: