Getting the Size of the Java Memory Heap
The 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();
Is it possible to find how much of memory occupied by a file
public long occupiedMemory(String filePath){
//TODO - Calculate
return occupiedMemoryBytheFile;
}
Chamira: You could use this:
public long occupiedMemory(String filePath){
File file = new File(filePath);
return file.length();
}
aavcrtc
I need Extera memory for java
testtetsttestsetstsetsesesese
How to get Running code memory in java?
How to get Running program code memory in java?