Re: Nulling an object
Lew wrote:
The closing brace gives ample clarity to the intent that a variable
go out of scope.
Mike Schilling wrote:
We were specifically discussing the case where it is necessary,
because the variable won't go out of scope anytime soon. This can
That sounds like it would be better fixed by properly scoping the variable
than by a null-assignment hack. In the specific discussion to which you
refer, that was the answer in fact; Tom Anderson discussed how his project
solved it by a far better means than the null-assignment hack.
also occur with nested scopes within a method, since variables within
them don't go "out of scope" for GC purposes until the method returns.
In all JVM implementations? In the presence of Hotspot? Forever more?
Normally the source should not make assumptions specific to a particular
version of the JVM. In the case of a putative optimization, there should be
measurement and evidence first, re-evaluation of the algorithm second, and
micro-optimization third. Tom Anderson's anecdote was a good example; it
showed how changing the algorithm solved the measured performance problem
without resorting to implementation-specific hacks.
In light of the experts' advice that indiscriminate use of null assignment is
superfluous and occasionally harmful, I'd look for a very strong reason to do
otherwise.
--
Lew