Re: general performance question
- From: "Matt Humphrey" <matth@xxxxxxxx>
- Date: Wed, 30 Jan 2008 13:15:08 -0500
"Tobi" <TobiMc3@xxxxxxxxx> wrote in message
news:628a2617-ff4a-460a-9c50-661e7f424f2f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Is it *really* true that creating an object closer to where it will be
used by the code, rather than creating it and setting it to null,
makes a noticeable difference performance-wise?
Clearly there's no sense at any time in creating an object and then setting
it to null, so I think you're mixing up variable declaration with object
creation. Declaring a variable does not automatically create the associated
object--as in
Point p;
This only declares the variable p--no object is created. Stylistically, I
prefer that variables be declared near to where they're used, but that
doesn't affect performance, particularly because objects are created on the
heap (or wherever the JVM finds most convenient).
What is the best practice with respect to this?
The best practice is to not fool with this kind of optimization unless you
have hard data from a profiler that it's actually a problem.
Matthew Humphrey http://www.iviz.com/
.
- Follow-Ups:
- Re: general performance question
- From: Mike Schilling
- Re: general performance question
- From: grasp06110
- Re: general performance question
- References:
- general performance question
- From: Tobi
- general performance question
- Prev by Date: Re: XML support in Java 5?
- Next by Date: SAP BW Consultant -- REQUIREMENT !!!
- Previous by thread: general performance question
- Next by thread: Re: general performance question
- Index(es):
Relevant Pages
|