betweenGo

Java allocation is no longer expensive

by Frank Kim on Oct.10, 2005, under Java SE

Beginning in JDK 1.4.2, allocation of new objects is no longer expensive according to this article, Java theory and practice: Urban performance legends, revisited. According to this article.

… allocation in modern JVMs is far faster than the best performing malloc implementations…

The malloc/free approach deals with blocks of memory one at a time, whereas the garbage collection approach tends to deal with memory management in large batches, yielding more opportunities for optimization (at the cost of some loss in predictability).

This “plausibility argument” — that it is easier to clean up a mess in one big batch than to pick up individual pieces of dust throughout the day — is borne out by the data.

So allocate away, never object pool, don’t do strange, non-intuitive things to avoid allocating objects on the heap. Life is good.

  • Share/Bookmark

Related posts:

  1. Enums in Java
  2. Effective Java Collections
  3. Playing with Dates in Java
  4. Covariant Return Types in Java
  5. Java Method with Generic Return Type

:

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!