Is there a way of finding how many bytes were allocated in a Java application? If possible, without changing the code? Thanks.
Asked
Active
Viewed 671 times
0
-
many discussions about that: http://stackoverflow.com/questions/19785290/java-unit-testing-how-to-measure-memory-footprint-for-method-call http://stackoverflow.com/questions/3536149/best-way-to-measure-memory-usage-of-a-java-program http://stackoverflow.com/questions/21272877/understanding-jvm-memory-allocation-and-java-out-of-memory-heap-space – guillaume girod-vitouchkina Dec 06 '15 at 21:16
-
By "allocated in a Java application", can you clarify a little? Do you mean total memory usage within the VM environment, or something else? – J. Murray Dec 06 '15 at 21:17
-
yes, I mean total memory usage. – franco Dec 06 '15 at 21:19
2 Answers
2
for example, from this post: Java unit testing: how to measure memory footprint for method call
Runtime.getRuntime().freeMemory();
Runtime.getRuntime().totalMemory();

Community
- 1
- 1

guillaume girod-vitouchkina
- 3,061
- 1
- 10
- 26
1
You can use several available methods in java.lang.Runtime [1] class or (more sophisticated) JMX [2]
[1] http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html
[2] https://docs.oracle.com/javase/tutorial/jmx/overview/javavm.html

Andrea
- 2,714
- 3
- 27
- 38