"When a thread’s run method had executed its last instruction, the thread dies as an object" is said to be false in one of my thread exercise; why is that not correct?
-
Maybe because the `Object` itself is not destroyed until the next GarbageCollector cycle. Not sure that is the expected answer though – Anthony Raymond Dec 13 '17 at 14:35
-
The `Thread` object isn't going to be GCed as soon as you finish running. All references to it must be removed first. – Dec 13 '17 at 14:35
2 Answers
That's an odd question. "Dies as an object" is not a conventional term.
The instance of the Thread object behaves just like any other Java object. It will be garbage collected as soon as it's not reachable any more. See https://stackoverflow.com/a/5690468/3765428 for more about garbace collection.

- 803
- 6
- 10
-
Minor nit pick, but there is one small difference between a `Thread` object and some other object. It's not a difference in how the language works, but it is a _practical_ difference. If your program creates a new `Thread` object, starts the thread, and throws the reference away; then the `Thread` object will continue to be reachable via hidden references from the new thread's stack. It will continue to be reachable for at least as long as the thread is running. – Solomon Slow Dec 13 '17 at 16:51
Need to define 'dies', In general - objects which are being pointed at by variables AKA:
Object thread = new Thread()
are alive as long as some other object holds or points to the thread object.
e.g. Object[] threads = [thread, ...] //Psudo code
so, as long as threads object is pointing/holding/etc the thread object and it's not being disposed, it's still be 'alive'.
And even when no one points to the object, it still has to wait for the GarbageCollector (GC) cycle in order for it to call the Dispose()
method (which exists in every object) to 'kill' it

- 505
- 5
- 15