-
-
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
Path.exists() - Memory leak #122849
Comments
Pathlib interns strings, so that's probably the cause of the inflated memory usage. Duplicate of #119518 (and also take a look at #113993). |
For what it's worth, the issue seems to be only present in Python 3.12 (not before, nor in 3.13). Running the following script with docker official from pathlib import Path
import tracemalloc
directory = Path("/")
found = False
tracemalloc.start()
snapshot1 = tracemalloc.take_snapshot()
for item in range(1_000_000):
found |= (directory / str(item)).exists()
snapshot2 = tracemalloc.take_snapshot()
top_stats = snapshot2.compare_to(snapshot1, 'lineno')
for stat in top_stats[:10]:
print(stat)
|
Yes, but it's a big PR and there are several fixes on top. I'm now working on the backport in #123065. |
Small note: while patched to "standard" 3.13, on experimental free-threaded build 3.13.0rc2t that is still the case - memory usage increases indefinitely because of interned strings use in pathlib |
@RegisGraptin This was fixed in 3.12.7 release on October 1st. https://docs.python.org/release/3.12.7/whatsnew/changelog.html#python-3-12-7 The issue can be closed. Thanks! |
Thank you for the work 🙏 , doubled tested on my side on 3.12.7 with the code of the issue, and no more memory leak noticed 🎉 |
Bug report
Bug description:
I am currently having an issue when using
Path.exists()
function. It seems that if you use it for intensive usage, I have a memory leak.Here is a python script, where I iterate over some items, and when I called the
exists()
function it seems the RAM keeps growing.Here also a screen shot that I have using
memory_profiler
library to illustrate it.I do not know if I am missing something here... Let me know if you need more info to reproduce it. I am using
Python 3.12.3
onUbuntu 22.04.4 LTS
.Thanks
CPython versions tested on:
3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: