How to find the number of objects in the heap

前端 未结 10 1804
离开以前
离开以前 2020-11-29 07:31

How can I find the number of live objects on the heap in Java program?

10条回答
  •  借酒劲吻你
    2020-11-29 08:15

    The simplest way is to use jmap tool. If you will print objects histogram at the end you'll see total number of instances and also accumulated size of all objects:

    jmap -histo will print whole objects with number of instances and size. The last line will contain total number

    Total 2802946 174459656

    Second column is total instances count, and last is total bytes.

提交回复
热议问题