-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Different memory/gc behavior depending on setting locals=globals #118426
Comments
I'm not sure that this is a bug, but I have absolutely no clue why the behavior is different |
You can find repo with cmakefile and rust variant here https://github.com/leviska/cpython_mem_leak |
I don't think there's a bug here, but rather a question of how much work the cyclic GC is having to do. Function definitions that are reachable from their own global scope inherently form a cycle (via their In the two dict case, that cycle never forms since It would be interesting to confirm what happens to the memory usage in the single dict case if the cycle is explicitly broken by adding (As to why a single |
Thanks for the answer! |
Bug report
Bug description:
If you call
PyEval_EvalCode
, memory will be cleared iflocals != globals
, but will accumulate iflocals == globals
(orlocals == Py_None
, which is the same)The code sample:
Code sample
The output of the given code on my machine:
Yet, if we call
PyEval_EvalCode(compiled_code, dict, dict2);
(dict2, not dict), then the output becomesAdding
At the end of the python code seems to help even in the first case, but still the memory can be larger:
Originally I found this using pyo3 library in Rust (I have a MRE in Rust too), so I'm pretty sure, that it's not related to my poor C code.
CPython versions tested on:
3.11
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: