To the best of my knowledge, once static data is loaded it cannot be unloaded by the JVM. This makes sense, because otherwise you would be recreating data that is meant to be initialized once across all instances of that class. In many ways a purely static class is like a singleton and you cannot reclaiming the memory. Thus, it would be more expensive long-term for short lived objects.
Most static utility classes I see are only needed in modestly used scenarios, so instantiating a light-weight object is better. Similarly static final variables, which often are just private Strings or numbers, are light enough that you don't gain anything by keeping them in memory for long periods.
Personally, I try to use statics only for data that is heavy to instantiate and needed once, singletons, and factory methods. Sometimes the less you use a trick, the cleaner and more flexible the code!
There's no place like 127.0.0.1
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
There's no place like 127.0.0.1
"I'm not back." - Bill Harding, Twister
Originally posted by John Grath:
If a method only performs operations on non-instance field values it can and should be a static field candidate. Think about how many of the math methods are implemented.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
java.lang.Math is a very special case - mainly because of the existence of primitives. If numbers were objects, the needs for most of the Math methods would vanish - they could be directly implemented on the numbers, as instance methods.