devxlogo

Avoid Object Instantiation Within Loops

Avoid Object Instantiation Within Loops

Avoid defining new objects within loop structures. Doing so hampers performance significantly, due to object creation overhead.

Instead, define objects outside the loop and then use them inside the loop. Moving object definitions out of your loops can often improve loop performance by nearly 100 percent.

If you want to see the actual effect, try using a profiler plugin such as jprobe or the Eclipse Test & Performance Tools Platform (TPTP) profiling tool.

devx-admin

Share the Post: