Typically, you start by optimizing your program for maintenance. *Than* you observe wether you have a performance or memory problem, use a profiler to find the bottlenecks and remove them (as the system is optimized for maintainability, it shouldn't be that hard to do those local changes).
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
Also, don't assume that performance and memory necessarily need to be traded against one another. There are many cases where reducing memory usage can result in improved performance. Building on Ilja's post above, I'd usually design and build for maintainability first, then memory, and then speed (if it turns out theres really a problem at that point.)
>> How do I calculate memory usage of My swing application ? << System.gc(); Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); Note that totalMemory is how much the Java process is taking from the environment; totalMemory - freeMemory is the amount of memory that is actually being used.
subject: Optimization Java Code - performance Vs memory