Numeron wrote:
On Sep 3, 1:47 pm, markspace <nos...@nowhere.com> wrote:
[snip all the helpful stuff]
So I'm going to assume that you misspoke and by dereference you mean
"remove the reference."
r = null;
Thats the one yes.
Thanks, Ill have to add something in to break loop and conclude the run
() method before removing the reference :)
Like I said, normally you don't have to do this. The object will be
removed sometime after it finishes running. Just null out the reference
any time, or better yet just allow it to go out of scope.
public void exe()
{
Runnable task = new Runnable() { public void run() {
System.out.println( "Hello Runnable!" ); } };
new Thread( task ).start();
}
Not tested, but it should work. There's no need to set "task" to null.
It'll be collected when it finishes. This is much cleaner than trying
to litter your code with "x = null;" everywhere, as the latter will
cause any programmers who come after you to curse your name.
an attempt to help the garbage collector (GC). You set references to 'null'
ought to be collected and forgetting where the live reference(s) is (are).
cursing rather than helping, and simply going out of scope is all you need.