Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Optimization Java Code - performance Vs memory

 
raj varma
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I calculate memory usage of My swing application ?
How do I optimise java code so that it gives good balance between - Memory Versus Performance.
Please give me hints .
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Joe Cheng
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic