-
Notifications
You must be signed in to change notification settings - Fork 763
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
Potential memory leak when calling Python from Rust #1801
Comments
I ran valgrind according to the documentation on the following program to check for leaks:
Output:
I've also attached a logfile for running valgrind with |
Thank you :). I think you're right.
https://github.com/PyO3/pyo3/blob/main/src/python.rs#L394 Note however, that your second example (with a loop inside the |
Thanks for the tip, adding If it's any help, I'm happy to make a PR. Otherwise, I can just run pyo3 with the patch for now. |
Please do! Pull requests are always welcome. |
I checked that |
Good find, I agree that needs a DECREF too. |
Reopening for the second instance. |
This commit fix the memory leak happening in the dora API operator. This is seemingly due to pyo3 leaking memory on object created in Rust. Using standard `drop` did not drop the memory on the `PyBytes` included in the `PyDict`. See: PyO3/pyo3#1801 Fixes #163
This commit fix the memory leak happening in the dora API operator. This is seemingly due to pyo3 leaking memory on object created in Rust. Using standard `drop` did not drop the memory on the `PyBytes` included in the `PyDict`. See: PyO3/pyo3#1801 Fixes #163
🐛 Bug Reports
Repeatedly calling Python from Rust appears to cause a memory leak of ~700 bytes per invocation. This poses a problem for long-lived Rust programs that repeatedly call Python. In my case, I ran into this issue while adding support for Python UDFs to a Rust-based streaming system.
As a side note, thanks for all the hard work on this fantastic library! Hoping this can be resolved, and that I haven't missed something on my end.
🌍 Environment
rustc --version
): 1.54.0version = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
: yes💥 Reproducing
The following also causes the issue:
Run with
cargo run --release
and observe memory use grow.The text was updated successfully, but these errors were encountered: