Re: general performance question
- From: Daniele Futtorovic <da.futt.newsLOVELYSPAM@xxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 20:50:24 +0100
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.
.
- References:
- general performance question
- From: Tobi
- Re: general performance question
- From: Matt Humphrey
- Re: general performance question
- From: Mike Schilling
- Re: general performance question
- From: Lew
- general performance question
- Prev by Date: rename the certificate and private key in the keystore so that they have the same alias
- Next by Date: Re: JTree node partially visible
- Previous by thread: Re: general performance question
- Next by thread: SAP BW Consultant -- REQUIREMENT !!!
- Index(es):
Relevant Pages
|