Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

A question about Thread garbage collection  RSS feed

 
chaohua wang
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Folks,

I had an interview with HP yesterday. They asked me a question.
I didn't get a right answer. I think.
I know t.start() will call run function, although t=null, Right?

Thread t = new Thread(); t.start(); t = null; now what will happen to the created thread?

Please help!

Thank you.

Chwang
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread will continue to run. You just do not have a handle to it anymore. It is also eligible for Garbage Collection.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ku:
It is also eligible for Garbage Collection.


No, it's not. As long as it's not dead, it belongs to a ThreadGroup, which keeps it from being collected.
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the correction. I meant to say that without the original reference, it would be eligible with the usual constraints that it is not referenced elsewhere. I was just too lazy to type all that in.

I think the main point in the question is - will it continue to run?

Yes
 
chaohua wang
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very. I think i did right. but not sure i will be hired.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!