Archie Cobbs wrote:
> Archie Cobbs wrote:
> > What happens when you run this program:
> >
> > public class ThreadLeak {
> > public static void main(String[] args) {
> > while (true)
> > new Thread();
> > }
> > }
> >
> > I get an OutOfMemoryError.
>
> 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?
>
> I'm not sure why Sun hasn't done that already.
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();
}
Now I don't know why anyone would want to do this, but I don't see why
you'd do while(true) new Thread() either ;-)
Regards,
Jeroen
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://lists.gnu.org/mailman/listinfo/classpath