• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting rid of a Thread

 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic