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
mallocimplementations…The
malloc/freeapproach 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.
Related posts: