Search

ParaSoft

HOME
PRODUCTS
SUPPORT
ABOUT
WHAT'S NEW
EVENTS


Jtest

Quick Facts

Technical Papers

Support & Manuals

FAQs

Recent Reviews

User Testimonials

Press Releases

Jtest tool to debug Java(tm)





Contents  Previous  Next  Index

OPT.LOOP: Avoid instantiating variables in the loop body


DESCRIPTION

This rule flags any variable that is instantiated in the loop body.

Instantiating temporary Objects in the loop body can increase the memory management overhead.

EXAMPLE

 package OPT;
 import java.util.Vector;
 
 public class LOOP {
     void method (Vector v) {
         for (int i=0;i < v.isEmpty();i++) {
             Object o = new Object();
             o = v.elementAt(i);
         }
     }
 }

DIAGNOSIS

Variable instantiated in loop body: o

REPAIR

Declare a variable outside of the loop and reuse this variable.

 package OPT;
 import java.util.Vector;
 
 public class LOOP {
     void method (Vector v) {
         Object o;
         for (int i=0;i<v.isEmpty();i++) {
             o = v.elementAt(i);
         }
     }
 }

Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft