Image

Java, etc. programming

Originally posted here on my personal journal.

Every collection of Java performance advice I've ever seen has started with ways to speed up disk access and then proceeded to give the advice that you should avoid object creation wherever possible, as the dynamic memory allocation and deallocation are expensive. The same seems to be true in Visual Basic, and probably .Net languages and Delphi as these languages all use reference-based object systems.

The advice I've seen for Java has been to reuse the same object repeatedly, and in larger cases, maintain a pool of objects that have already been created. Whenever you need to start using the object again, you would clear out all the existing values. I suppose this is good advice, but shouldn't Java itself be doing that?

I have argued on C++ newsgroups that, while using the STL tools and avoiding pointers may well be the most productive way to use C++, a program that can be written that way would probably be better off in a higher-level language. Likewise, while object-pooling may inmprove your Java (VB, VB.Net, C#, Delphi) performance, the whole point of these languages is that you don't have to deal with memory management yourself.