Stopped threads never garbage collected
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rod_Spearman
Posted On:   Wednesday, September 18, 2002 01:43 PM

While running a multithreaded java server, we've noticed that when garbage collection runs, the previously executed (now stopped) thread(s) remain on the heap. This anomaly leaks about 80k for each thread not cleaned up. However, all the objects the stopped thread constructed are being garbage collected. Our server has the potential of processing tens of thousands of requests. Eventually the server crashes on an JavaOutOfMemory exception. The threads are going out of scope, therefore there shouldn't be any references to them. Are we missing something here? Any help/insight would be greatly appreciated.

Re: Stopped threads never garbage collected

Posted By:   Blake_Minghelli  
Posted On:   Thursday, September 19, 2002 09:03 AM

I agree that it looks like there are still references to the threads being held somewhere (probably in the class that started them). Just because the run() method completes, doesn't mean that the thread is gc'ed - gc still depends on whether or not there are still references to an object. I would double-check the class that starts the threads and see if the references are still there. For exapmle, are the threads added in a ThreadGroup? If so, then the ThreadGroup would still have references to each thread.

Re: Stopped threads never garbage collected

Posted By:   Mike_Friedrich  
Posted On:   Thursday, September 19, 2002 12:16 AM

I noticed this behavior if swing/awt will be used inside. Some swing components caches the last used thread-object.


It's generally good to set all internal members of the thread to null at the last step inside of the run-method.


Find out which objects holds a reference to your thread-objects (some kind of cache? swing has one - may be there are more).


Regards, Mike

Re: Stopped threads never garbage collected

Posted By:   eimi_nos  
Posted On:   Wednesday, September 18, 2002 03:06 PM

Even after a thread terminates, the reference to the thread must remain. What about setting null to the reference to the terminated thread?
About | Sitemap | Contact