• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding java.util.List

 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a small issue which i wanna make sure about.

Which method is best performance wise? Calling the clear method on a list or making it null and re-creating it ?

Thanks,
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a good example of a micro-optimization that is unlikely to yield measurable performance gains unless it's done millions of times. Plus, whatever its effects are, could be reversed when using a different JRE version.

If I were concerned about performance, I'd start by by measuring where execution time is spent, and then analyzing algorithms and data structures with that in mind (after I've made sure that performance is indeed unacceptably bad).
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I'll agree with Ulf on avoiding micro-optimizations - especially in Java, where the JVM may actually rewrite code at runtime based on observed performance, from a reliability level, I recommend discarding the old list.

The days are long one when object construction was a serious consumer of resources, but it's better to start from scratch with a clean object than possibly get weird behavior due to reusing an object that wasn't cleaned out properly.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic