Richard O. Hammer wrote:
> Generally, all you need to do with a variable name when you are done
> with it is to forget it.  Just let it fall out of scope, while making
> sure of course that your scope is not larger than needed.

Sage advice.

> When I see variables set to null after their use, I think that this
> programmer does not know Java.

One source of this practise is that it was necessary in some dialects of
other languages featuring GC, such as Smalltalk, where those implementations
only supported strong references. In more advanced Smalltalk dialects and
Java we have the ability to use various kinds of weak(er) references which
remove the need to explicitly release a strong reference.

Bottom line. Choose the appropriate kind of reference, manage scope and
leave the garbage collector to do its stuff. Use JVM options to tune the
heap size and GC algorithms as best fits the application. Trying to manage
memory use explicitly works against Java's ability to "write once, run
anywhere" as those explicit choices are static and will be optimised to a
single deployment scenario at best and at worst add unnecessary and
unproductive tasks to the garbage collectors work queue.

-- Steve


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to