|
From: | Archie Cobbs |
Subject: | Re: Memory leak in java.lang.Thread ? |
Date: | Wed, 08 Dec 2004 09:05:47 -0600 |
User-agent: | Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129 |
Jeroen Frijters wrote:
Now I realize that Sun's JDK has the same bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4410846 Can we fix this simply by having the references from the ThreadGroup -> Thread be via weak references?Because it would mean that the semantics change. There could be code that does: new Thread("MyThread"); ... ... ThreadGroup g = Thread.currentThread().getThreadGroup(); Thread[] threads = new Thread[g.activeCount()]; g.enumerate(threads); for(int i = 0; i < threads.length; i++) { if(threads[i].getName("MyThread")) threads[i].start(); }
Good point.. this is one of those bugs in the API that requires the implementation to have a memory leak. However, I couldn't find any definition of an "active" thread. Empirically it seems to mean "either not yet started or still running". Seems like the "not yet started" part is questionable though. By the way this is a real problem e.g. in an application where you create a thread and then decide to start it later (or not) based on some last minute information. -Archie __________________________________________________________________________ Archie Cobbs * CTO, Awarix * http://www.awarix.com
[Prev in Thread] | Current Thread | [Next in Thread] |