Re: Nulling an object
Lew wrote:
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?
That's how it's been documented.
Normally the source should not make assumptions specific to a
particular version of the JVM.
Though it's only sensible to put in workarounds for issues with JVMs
that the code is going to be run on, provided that they're
well-documented. Code runs on real JVMs, not hypotherical perfect
ones.
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.
Not at all. It was an example of another way to solve the problem
that Tom felt was more "elegant". I disagree, and don't see why my
criteria of making the problem and its solution clear in the code are
of less value than Tom's (and apparently your) esthetic feelings.