How might I compute or determine the memory consumption of a program written in Java using NetBeans?
How to compute or determine the memory consumption of a program written in Java using NetBeans?
1.1k views Asked by Junaiduba At
4
There are 4 answers
0
On
If you want to check memory consumption and other statistics you cant try.
$JAVA_HOME/bin/jconsole
It let you choose the process PID of your application and see the Memory and CPU usage at runtime.
NOTE: You don't need to have Netbeans installed so it can be used in production environments also.
0
On
If you want to compute the memory from your Java program you can calculate it at any time with this code:
double currentMemory = ( (double)((double)(Runtime.getRuntime().totalMemory()/1024)/1024))- ((double)((double)(Runtime.getRuntime().freeMemory()/1024)/1024));
It will give you the memory usage in megabytes. You could use this code to check the memory usage at different time and keep the maximum memory usage or make some statistics.
Also it will work even if you don't use NetBeans.
Since you use Netbeans, there is a Profile Main Project button right next to the debug button of you tool bar. The option Memory allows you to monitor the memory graphically while your Main project runs. The Window-->Profiler-->Telemetry overview gives you a graph of your memory consumption similar to this one:
and even:
Among all sorts of other details...