Re: general performance question



On 31.01.2008 03:18, Lew allegedly wrote:

Brian Goetz is among the notables who have debunked the "set to null
to help GC" myth: <http://www-128.ibm.com/developerworks/java/library/j-jtp01274.html>
Because allocation and garbage collection at one time imposed significant performance costs on Java programs, many clever tricks
were developed to reduce these costs, such as object pooling and nulling. Unfortunately, in many cases these techniques can do more
harm than good to your program's performance.
....
Sun warned of this risk and explained how explicit nulling was
needed in [certain] cases... . Unfortunately, programmers often
take this advice too far, using explicit nulling in the hope of
helping the garbage collector. But in most cases, it doesn't help
the garbage collector at all, and in some cases, it can actually
hurt your program's performance.

Think of it this way - setting a variable to null has nothing to do
with the business logic of the program - it's a hack that is based on
a superstition relating entirely to implementation. Breaking the
logic of your program in order to imagine a performance improvement
is a classic programming mistake.

The following quote from the article you referred to shouldn't be
omitted from this context, IMO:
"There is one case where the use of explicit nulling is not only
helpful, but virtually required, and that is where a reference to an
object is scoped more broadly than it is used or considered valid by the
program's specification."

You're right in that program logic should be the standard concern and
concurrence with GC-logic but an exceptional one (this goes without
saying as for imagined GC behaviour, but should IMO also be applied to
real GC-logic). After all, the latter should be tailored to comply with
the former, to the extent in which the former follows from language
specifications.

DF.
.



Relevant Pages

  • Re: general performance question
    ... significant performance costs on Java programs, many clever tricks ... the garbage collector at all, and in some cases, it can actually ... "There is one case where the use of explicit nulling is not only ...
    (comp.lang.java.programmer)
  • Re: general performance question
    ... significant performance costs on Java programs, ... were developed to reduce these costs, such as object pooling and nulling. ... the garbage collector at all, and in some cases, it can actually ... "There is one case where the use of explicit nulling is not only ...
    (comp.lang.java.programmer)