> Stacy,
>  
> I would think that there would be, as the first example declares a new 
> instance of MyObject every iteration, which I believe will allocate 
> memory on every pass, whereas the second example will not. However, I 

sorry, no. there is no object instantiation here, because there is no
"new"-keyword (which would 
create an object on the so-called heap, the "long-term" memory of the VM)
the variable is *declared* locally with a certain type (which means it may
hold references of that type)
and is allocated on the so-called stack (which is a portion of the memory
where "short-lived" information is stored, e.g. local variables like the one in
the example, the information where to jump back to after a function call
etc.)
the overhead lies in the creation of the local variable on the stack in
every iteration.
of course - as already suggested - the compiler might optimize this. anyone
who dug into the VM documentation deep enough? ;o)
greetings

> cannot say for certain that the compiler will optimize this. Perhaps a 
> simple benchmark would be the best solution?
> 
> Regards, 
> John 

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to