After instantiating a Thread and start it what will happened to the created instance of it. Will it have same behavior as other instance?
Thread a = new MyThread();
a.start();
a = null
where this created instance of Thread resides(in heap or doesn’t it be in tenured space). will it be garbage collected?. If it is get garbage collected what happened to used instance properties?
A thread will not be garbage collected while it is “live”, irrespective of whether the
Threadobject can be accessed. This is a consequence of the JLS’s definition of reachability.For the record, a typical JVM allocates a thread’s stack in memory that is outside of the heap(s). The
Threadobject and its children are regular heap objects. These may be garbage collected: the specifications are silent on this, AFAIK. Finally, part of a thread’s state may reside in memory managed by the OS kernel.That doesn’t prove that it has been garbage collected. All it proves is that JProfiler couldn’t find it.
If the thread has terminated (and you haven’t kept a reference to the
Threadobject) then it / they will no longer be reachable, and JProfile won’t be able to find it.