• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding java.util.List

 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • 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,
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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).
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!