How can I actually, really deallocate a Thread to release the memory? Setting thread = null does not work!

Larry Widing

Using thread = null will not release a running thread. In order to release the memory associated with a thread, you need to make sure that all of the following are done:

  • Make sure that the thread's start() method has been called.
  • Make sure that the thread has stopped executing.
  • Clear any references to that Thread object (thread = null;).

This is the best you can do to ensure the release of memory for a Thread. You have to call start() on the thread because several JVMs have a bug where they will not release all the thread's memory if the thread is not started.