Re: Declaring outside a loop: speed? memory?
- From: "Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx>
- Date: 23 Jan 2007 14:50:31 -0800
Steve W. Jackson wrote:
Declaring the variable "mine" before the loop makes its scope wider than
just the loop. As a result, the last instance after the loop terminates
is still in existence until the wider scope is finished. Only then is
it certain to be eligible for garbage collection, should the JVM need to
do so. So if there's a good deal that follows this loop, there could be
a benefit to the first approach.
Actually, I think the compiler/JVM is smart enough to make references
elegible for GC if the ref isn't used for the rest of the scope.
.
- Follow-Ups:
- Re: Declaring outside a loop: speed? memory?
- From: Doug Pardee
- Re: Declaring outside a loop: speed? memory?
- References:
- Declaring outside a loop: speed? memory?
- From: Philipp
- Re: Declaring outside a loop: speed? memory?
- From: Ben Caradoc-Davies
- Re: Declaring outside a loop: speed? memory?
- From: Steve W. Jackson
- Declaring outside a loop: speed? memory?
- Prev by Date: Re: Check if a final field is initialized
- Next by Date: [Newbie] self-updating J2ME application?
- Previous by thread: Re: Declaring outside a loop: speed? memory?
- Next by thread: Re: Declaring outside a loop: speed? memory?
- Index(es):
Relevant Pages
|