0

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?

1

2 Answers 2

2

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(); 
Sign up to request clarification or add additional context in comments.

Comments

0

java.lang.management.MemoryMXBean might be useful

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.