• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dereferencing threads  RSS feed

 
Tiffany Gorch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if I dereference a thread without doing any sort of cleanup/shutdown? Does it just get garbage collected at some unknown point (hopefully not when it is actually running)?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, an object will be eligible for garbage collection if it is no longer reachable. As the JLS (12.6.1) puts it, A reachable object is any object that can be accessed in any potential continuing computation from any live thread. This applies to Thread objects, too - as long as the thread runs, its Thread object will be reachable (cf. Thread.currentThread()) and cannot be garbage collected.
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!