Sanzee's blog

By Sanzee, 13 years ago, In English
we  are working on a educational OJ .We are facing difficulty finding total memory used by a java code in Linux (CenOS). As Linux process table shows the sum of the JVM memory and the code memory.How can I find the specific memory used by a java code ??????
please help.



  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
You can run this code inside JVM:
// Get current size of heap in bytes
long heapSize = Runtime.getRuntime().totalMemory();

// Get maximum size of heap in bytes. The heap cannot grow beyond this size.
// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();

// Get amount of free memory within the heap in bytes. This size will increase
// after garbage collection and decrease as new objects are created.
long heapFreeSize = Runtime.getRuntime().freeMemory();

13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
There is JMX - technology for monitoring and management Java-applications.
13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
thanks !!