Is there a Java library(.jar) file I can download and use the API to track the heap size for my program? If there isn't one how would I go about creating one?
2 Answers
You can use the Runtime class:
Current heap size (it can grow until the allowed maximum is reached):
long hSize = Runtime.getRuntime().totalMemory();
Maximum heap size:
long hMaxSize = Runtime.getRuntime().maxMemory();
How much of the current heap size is free:
long hFreeSize = Runtime.getRuntime().freeMemory();