Declaring outside a loop: speed? memory?
- From: Philipp <sicsicsic@xxxxxxxxxxx>
- Date: Tue, 23 Jan 2007 11:23:58 +0100
Hello
Just wondering, is there a speed or memory difference between the two following codes? What is recommended? Which will easier garbage collect (suppose MyClass is big)?
--- code ---
for(int i = 0; i < 1000; i++){
MyClass mine = new MyClass();
mine.doSomething();
}
------------
and
--- code ---
MyClass mine;
for(int i = 0; i < 1000; i++){
mine = new MyClass();
mine.doSomething();
}
------------
Thanks for your answers
Phil
.
- Follow-Ups:
- Re: Declaring outside a loop: speed? memory?
- From: Ben Caradoc-Davies
- Re: Declaring outside a loop: speed? memory?
- Prev by Date: Re: Which is better (in Java), depending on instanceof a lot, or having my own getType function
- Next by Date: Re: Custom Tag lib life-cycle question.
- Previous by thread: JSP to Excel
- Next by thread: Re: Declaring outside a loop: speed? memory?
- Index(es):
Relevant Pages
|