Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread garbage collection

Will a Python threading.Thread ever be garbage collected if there is no longer any reference to it but it's still running?

# Start a thread with no reference
Thread(target=some_long_running_function).start()
# Do lots of other stuff
like image 450
Xophmeister Avatar asked Feb 05 '17 13:02

Xophmeister


People also ask

Do threads get garbage-collected?

The Thread is not garbage collected because there are references to the threads that you cannot see. For example, there are references in the runtime system. When the Thread is created it is added to the current thread group.

What happens to the thread when garbage collection?

7. What happens to the thread when garbage collection kicks off? Explanation: The thread is paused when garbage collection runs which slows the application performance.

What is garbage collector thread?

2) Garbage collection is a mechanism provided by Java Virtual Machine to reclaim heap space from objects which are eligible for Garbage collection. 3) Garbage collection relieves Java programmer from memory management which is essential part of C++ programming and gives more time to focus on business logic.

Does garbage collection block threads?

Blocking during background - background GC does not suspend other threads during Gen2 collections. Nevertheless,Gen0 and Gen1 collections (which are an inevitable part of a full GC) still require managed threads to be suspended.


1 Answers

I believe the Threading module contains a reference to the thread whilst it is running and is then cleaned when the Thread run() method has finished. I cannot comment on the internals of the module and how it accomplishes this but I believe these references (references to active threads) can be accessed via threading.enumerate()

like image 114
Sighonide Avatar answered Nov 05 '22 20:11

Sighonide