Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting rid of a Thread  RSS feed

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a Thread class is created as in inner class that's started by the outer class; will it automatically stop if the outer class object is set to null?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Keohan:
If a Thread class is created as in inner class that's started by the outer class; will it automatically stop if the outer class object is set to null?
No. In fact, the relation between threads and garbage collection is just the other way around: an object only becomes eligible for garbage collection when no thread can reach it (regardless of whether that's the "main" thread or any thread you create). As long as the thread you create is still running, the outer class instance cannot be garbage collected: even if you set all references to null, the inner Thread subclass still has an implicit reference to it making it reachable.
- Peter
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!