IBM on Java’s Object Allocation and Garbage Collection.
The upshot of the article is that allocation hasn’t been particularly slow in Java since the 1.2 JVM. Since the business-standard JVM seems to be 1.4.2, that means practically all business applications have this enhancement already in play.
One of the major things that will kill your performance, though, is overbroad scoping. So all the people who wrote code looking like this:
String msg = null; for(int i = 0; i < 10; i++) { msg = "We are at position " + i; System.out.println(msg); } msg = null;
Just shot themselves in the foot. Not, however, that if you were to follow the pattern of aggressively using finalize (like the suggestion in Chapter 2 of Hardcore Java), you would write this code in exactly the way that is best optimized by the compiler.
Which, of course, is kind of what we would expect, because compilers 1) are better at optimizing than people, and 2) can make more sense of code that is structured reflecting the actual requirements, not backflips as hypothetical optimizations.
Related posts:
Pingback: Enfranchised Mind » 7 Actually Useful Things You Didn’t Know Static Typing Could Do: An Introduction for the Dynamic Language Enthusiast
Pingback: Enfranchised Mind » Functional (Meta)?Programming Stunts for Ruby and Groovy (and a Little Perl)