![]() |
The Java Developers Almanac 1.4 |
|
e55. Getting the Size of the Java Memory HeapThe heap is the area in memory in which objects are created. // 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();
e49. Terminating the Application e50. Determining When the Application Is About to Exit e51. Computing Elapsed Time e52. Loading Native Code e53. Implementing a Class That Can Be Sorted e54. Redirecting Standard Output, and Error
© 2002 Addison-Wesley. |