Answer the question
In order to leave comments, you need to log in
How to analyze the memory usage of a java program?
Stuck on such a task - to analyze the memory usage of a java program. There are no methods that return the amount of memory consumed by an object in java. It is also difficult to analyze from the outside - after all, there we also see the memory occupied by the JVM. What can be used to analyze how much a particular program consumes memory in its pure form, without taking into account the JVM and so on? Surely something has already been invented for this purpose. (Do not offer self-calculation)
Answer the question
In order to leave comments, you need to log in
You can use the garbage collector log.
On different JVM flags and output format are different.
Here's what you'll most likely see.
[GC 245118K->214677K(1571712K) eden 30464K->0K survivor 247K->270K tenured 214406K->214406K, 0.0212236 secs]
[GC 245141K->214708K(1571712K) eden 30463K->0K survivor 270K->301K tenured 214406K->214406K, 0.0229019 secs]
[GC 245172K->214692K(1571712K) eden 30463K->0K survivor 301K->285K tenured 214406K->214406K, 0.0241589 secs]
[GC 245156K->214747K(1571712K) eden 30463K->0K survivor 285K->340K tenured 214406K->214406K, 0.0245928 secs]
Information about memory can also be viewed using jstat . This is such a console utility that allows you to connect to any running java process (only run it as the same user as which java is running).
The same information can show all sorts of graphic visualvm and jconsole.
But what you will see there is consumption, which includes objects of the JVM itself and uncollected garbage.
And to see the details and "clean" consumption, you need a profiler (visualvm and jconsole can do this too).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question