Skip to content
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

Loading and unloading pymport leaks memory #77

Open
mmomtchev opened this issue Jan 22, 2023 · 2 comments
Open

Loading and unloading pymport leaks memory #77

mmomtchev opened this issue Jan 22, 2023 · 2 comments
Labels
invalid This doesn't seem right wontfix This will not be worked on

Comments

@mmomtchev
Copy link
Owner

Every time the pymport module is loaded and then unloaded, it leaks about 15Kb to 20Kb of memory.

The only way this can happen more than once is if the main thread never loads the module but repeatedly spawns worker_threads that load the module and then quit, allowing Node.js to unload the library.

@mmomtchev mmomtchev added invalid This doesn't seem right wontfix This will not be worked on labels Jan 22, 2023
@mmomtchev
Copy link
Owner Author

This is in fact a Python problem, Py_Finalize being a best-effort API call. In particular, the initialization of the Python GC and some singletons is not reversible.

@mmomtchev
Copy link
Owner Author

The best work-around when spawning temporary worker_threads that use pymport is to always load pymport from the main thread before using it in the worker_threads - this way Node.js won't be able to unload it when the worker_thread quits.

Not only this will solve the memory leaks, but it will vastly improve the performance as loading Python is quite expensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant