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

Memory leak when creating Module #699

Open
j-blue-arz opened this issue Feb 22, 2023 · 0 comments
Open

Memory leak when creating Module #699

j-blue-arz opened this issue Feb 22, 2023 · 0 comments
Labels
🐞 bug Something isn't working

Comments

@j-blue-arz
Copy link

j-blue-arz commented Feb 22, 2023

Describe the bug

I may hit a memory leak when creating a WebAssembly Instance. RSS does increase with each created Module object.

Steps to reproduce

I created a MWE repository:
https://github.com/j-blue-arz/wasmer-python-memory-leak

Example run:

$ python script.py
(Cmd) rss
rss: 15.93 MiB
(Cmd) run
Hello World!
(Cmd) rss
rss: 106.95 MiB
(Cmd) run
Hello World!
(Cmd) gc
(Cmd) rss
rss: 140.13 MiB
(Cmd)

In this application, if the Module object is cached to a field between calls to run, RSS does not increase after the first run.

Expected behavior

I would expect that
a) Memory can be freed when the local variable goes our of scope, i.e. memory should drop to lower level already after the first run
b) Memory does not increase even more for each (re-)creation of the Module

Additional context

Already the absolute memory consumption (~90MiB) is quite high. I guess that is the memory of the wasm instance. I further guess that this instance is not freed due to some cyclic pointers between the python stack and the extension.

One might argue that this leak is not so problematic, because the (stateless) Module instance should be cached between requests, or de-/serialized as suggested by the documentation. However, this adds some complexity in a real-world web application. My actual project is a flask-based REST-API, where potentially multiple service threads could access such a cashed instance. Also I aim to load .wasm files dynamically, so I would still need a way to free memory.

@j-blue-arz j-blue-arz added the 🐞 bug Something isn't working label Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant