[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: programing styles
Isn't #2 better for garbage collection, since you are not creating and
destroying an object on each iteration of the loop? My understanding is that
the number of objects you create directly impacts speeds. The less objects,
the less garbage collection, and the faster the application. Given that, I
would think #2 is much more efficient and the style to use.
Mike
-----Original Message-----
From: Magesh Umasankar [mailto:umagesh@apache.org]
Sent: Friday, November 01, 2002 2:42 PM
To: ajug-members@ajug.org
Subject: Re: programing styles
I would say the first one is - keep variable
declarations as local as possible - better
for garbage collection also, in most cases.
In your case, you gain nothing by declaring
them outside the for loop as you don't seem
to be using them outside the loop.
Cheers,
Magesh
**************************************************
* The surest sign that intelligent life exists *
* elsewhere in the universe is the fact that it *
* has never tried to contact us. *
**************************************************
----- Original Message -----
From: "Gudavalli, Manidhar" <manidhar.gudavalli@eds.com>
To: <ajug-members@ajug.org>
Sent: Friday, November 01, 2002 2:34 PM
Subject: programing styles
>
>
>
> HI
>
> Which style of coding is best ?
>
> [1]
> private void myproc(Vector vect){
> for (i=1; i < vect.size() ; i++){
>
> MyObject obj = (MyObject) vect.elementAt(i);
> int y = obj.getY();
> }
> }
>
> or
> [2]
> private void myproc(Vector vect){
> MyObject obj = null;
> int y= 0;
>
> for (i=1; i < vect.size() ; i++){
>
> obj = (MyObject) vect.elementAt(i);
> y = obj.getY();
> }
> }
>