I'm working on an SDK for Android with a few threads involve. I have an operation that creates and starts an unreferenced thread as so:
new MySdkThread().start();
I have to be absolutely certain that I'm not creating any sort of zombie thread and/or memory leak. So is a thread that has returned from it's run()
method dead and as such if it is unreferenced is it now eligible for reclamation by the garbage collector or do I have to join it? I realize that this is probably a very obvious answer, but I haven't found anything being absolutely specific about the requirements of joining a thread and I want to be sure.
is a thread that has returned from it's run() method dead and as such if it is unreferenced is it now eligible for reclamation by the garbage collector or do I have to join it?
No you don't have to join with it. If there are no references held to the Thread
object then it will be reclaimed by the garbage collected automatically and you don't have to worry about it at all. That's standard operation procedure.