Ulf Dittmer wrote:What makes you think that they're not being discarded? Objects that are no longer referenced are discarded eventually, although maybe not right away if the JVM has enough memory available.
As an aside, is there a socket/network aspect to this question? Just asking because you posted in the "Sockets and Internet Protocols" forum. (no big deal, we can move it).
Henry Wong wrote:
Let's move this topic -- along with the other thread questions posted in the socket forum too.
John McDowell wrote:
Ulf Dittmer wrote:What makes you think that they're not being discarded? Objects that are no longer referenced are discarded eventually, although maybe not right away if the JVM has enough memory available.
As an aside, is there a socket/network aspect to this question? Just asking because you posted in the "Sockets and Internet Protocols" forum. (no big deal, we can move it).
That's what is told in pg 500 headfirst java 2nd edition in the there are no dumb questions section
John McDowell wrote:
John McDowell wrote:
Ulf Dittmer wrote:What makes you think that they're not being discarded? Objects that are no longer referenced are discarded eventually, although maybe not right away if the JVM has enough memory available.
That's what is told in pg 500 headfirst java 2nd edition in the there are no dumb questions section
The question goes like...
Can you reuse a Thread object? Can you give It
a new Job to do and then restart It by calling start()
agaln?
And the answer goes like..
No.Once a thread 's runO method has completed,
the thread can never be restarted . In fact, at that
point the thread moves Into a state we haven't talked
about-dead. In the dead state, the thread has
finished Its runO method and can never be restarted.
The Thread object might stili be on the heap, as a
living object that you can call other methods on (If
appropriate), but the Thread object has permanently
lost its 'threadness'. In other words, there Is no longer a
separate call stack, and the Thread object Is no longer
a thread. It's Just an object, at that point, like all other
objects.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Chris Hurst wrote:A running thread will be ineligible for GC even if your code directly has no reference, its in the current thread group (you could look it up) and considered a GC root. Running threads appear slightly special in that they appear to exist when running without you holding a reference which can at first seem slightly odd.
The sentence from the book means ..
After the thread completes if your code has elected to hold a reference to thread that has completed you're preventing GC of that object but you can't restart the thread it represents via the thread objects interface. The holding onto the thread object might be considered wasteful/ leak but it's your code that is causing the leak (causing it to remain on the heap) in that scenario i.e. not the JVM.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |