How to find the number of objects in the heap

前端 未结 10 1789
离开以前
离开以前 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:21

    If all your objects are created using some kind of Factory class you can find number of objects in the heap. Even then you have to have something in the finalize() method. Of course, this cannot be done for all objects, e.g. the jdk library classes cannot be modified. But if you want to find number of instances of a particular class you have created you can potentially find that.

提交回复
热议问题