When a thread exits, we should set target to null:
private void exit() {
if (group != null) {
group.remove(this);
group = null;
}
target = null; // new line
}
We are observing that the conservative garbage collector occasionally has
quite long delays between a thread exiting and its Thread object being
collected. We have verified that there are no instance, static, or array
references to the thread object using the Kona reffinder. Therefore, it
appears that thread exit does something that tends to leave unfortunate
values on the stack or somewhere else.
Therefore, the object connected to the thread is also not collected.
Setting this to null allows this to happen. These objects are often
sizable, as they're the head of an entire graph corresponding to an
applet.
Tim's opinions on aggressive nulling, from email:
>I think that your program of aggressive nulling sounds appropriate.
>We would expect to get a lot of false keeps due to values in dead
>locals, etc. that the collector is too stupid to ignore, as well as
>stuff on the C stack. But I'm also sure that there is a lot of slop
>in the code, like in this Thread.exit example, that isn't really the
>fault of the collector. I'm really glad that you guys wrote your
>reference finder tool.
alan.bishop@Eng 1996-09-25