-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
concurrent.futures.ThreadPoolExecutor does not free memory when shutdown #98467
Comments
The process_user function returns the allocated memory. Don’t you want the return value to be available in the main thread? |
Correct, it should be available in the main thread. The primary issue is that allocated memory is never freed though. It should be freed once futures goes out of scope or when the executor is shutdown which should occur when exciting the with block but that doesn't happen. |
This isn't even because of threads, this is normal python behavior:
For example, this fib program "leaks"
Editing because I thought that python doesn't destroy on destructor scope. It does (both the threaded example and my example) if you write:
|
I believe the objects are garbage collected, but the memory isn't necessarily returned to the OS because Python uses a layer of abstraction around the system allocator. So you won't see process-level memory usage going back to the previous level. However, if you keep doing the same thing, memory usage should stabilize and not keep growing. |
Bug report
Memory allocated in threads is never freed when using a ThreadPoolExecutor. The expected behavior is that when the executor is shut down, all memory allocated in its threads should be freed. The below code demonstrates this leak in that the the memory usage before allocating memory in threads is significantly less than after.
Your environment
Python 3.9.x/3.10.x. Mac os and debian.
The text was updated successfully, but these errors were encountered: