Java Memory profiling

 

Method 1:

In a standalone system, it’s always better to check for the heap memory size which is storage for Java objects. Profiling can be done by taking the reading of free memory  when the program is just starting up and when at various stages of the program till the end.

How to get the reading: Use the method Runtime.getRuntime().totalMemory() to get the free memory in Java heap. The difference of the free memory over the period of time gives the memory consumed by the app while its running.

Method 2:

In a UI project especially in a Set Top Box or Decoder environment, It’s more important to know the On Screen Display (OSD) memory than anything else, because the Images that is displayed on the screen is quite memory intensive. Images are created using java.awt.GraphicsConfiguration.createCompatibleImage(width, height); and memory for the Image is calculated based on the height and width using the formula (width * height * 4) (4 bytes per pixel). So whenever the Image is created, note down the memory used by that. In order fot better organization of the code, Create a strategy pattern for creating the memory and calculate the total memory used in that pattern. And at the same time when the memory is cleared from the OSD memory, the total memory has to be decreased. The profiling can be done over the lifetime of the project to check for memory leaks.


Powered by Bullraider.com

neotrade NeotradeAnalytics is providing best and affordable priced realtime data (Futures and options , Currency) feed for worlds best charting tool Amibroker. We are official vendors of NSE India

Support us


JASMIM © by I-SAN.de
Follow Us on Twitter
Find Us on Facebook
Follow Us on Google
Follow Us on Pinterest