Is it possible to 'see' the object graph for garbage collection?

后端 未结 2 1418
傲寒
傲寒 2021-01-06 05:04

I have a Java application that is leaking memory. I know which objects are not being freed during garbage collection, but I can\'t work out what is referencing them.

相关标签:
2条回答
  • 2021-01-06 05:14

    On a really basic level, you can use the commands jhat and jmap to read a heap file from a running Java process and then process it - it starts a small web server on a local port. It's not exactly easy to read, but you don't have to buy a profiler to use it.

    0 讨论(0)
  • 2021-01-06 05:20

    Profilers do this. JProfiler for example. Back in the day I used Optimizeit (which seems to be dead now).

    The conclusion was that listeners were being passed to some collection and not being removed from that collection. The listeners were anonymous inner classes defined on a Frame or a corresponding control class that referenced the Frame, and an anonymous inner class has an implicit reference to its outer class. So that little listener held the whole frame and all its attendant objects in active memory.

    0 讨论(0)
提交回复
热议问题