英文:
In java, is there a way to examine how an object is still reachable from garbage collection root?
问题
代码库有点复杂,所以我想知道是否有一种工具可以在运行时检查对象,并确定JVM如何看待这个对象仍然是可访问的。
特别地,有一种对象类型,我只希望在应用程序的整个生命周期内一次只有一个实例(虽然可以创建新实例,但旧实例在发生这种情况时应该被垃圾回收)。然而,当我检查堆时,我发现这种对象类型的多个实例在累积。由于该类相当复杂,要找出仍然引用旧对象实例的原因将会相当耗时。是否有人知道一种工具或一种在Java中的方法,可以弄清楚为什么这些对象无法被回收?
英文:
The codebase is somewhat complex, so I was wondering if there was a tool to examine an object at runtime and determine how the JVM still sees this object as reachable.
In particular, there's one object type that I would only expect to be one instance of at a time throughout the life of the app (new ones can be created, but the old instance should be garbage collected when this happens). However, when I examine the heap, I see that multiple instances of this object type are accumulating. The class is pretty complex, so it'd be fairly time-consuming to track down what is still referencing the old object instances. Anyone know of a tool, or a way in java, to figure out why these objects can't be collected?
答案1
得分: 2
JProfiler有这样的视图:您可以追踪引用对象直至根对象。
此外,它还具有许多其他有用的调试视图,因此我一直认为它物有所值。
英文:
JProfiler has such a view: You can follow the referring objects up till the root.
And it has a lot of other useful debugging views, so I've always considered it worth the price tag.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论