是的,一个查询,例如:
SELECT * FROM com.google.common.cache.LocalCache$StrongAccessWriteEntry r where r in (SELECT AS RETAINED SET objects s FROM OBJECTS ${snapshot}.@GCRoots s WHERE ((SELECT t FROM OBJECTS ${snapshot}.getGCRootInfo(s) t WHERE (t.@type = 2048)) != null))
应该这样做。
解释:
找到 GC 根:
SELECT objects s FROM OBJECTS ${snapshot}.@GCRoots s
找到 GC 根,然后为每个 GC 根获取 GC 根信息的数组,然后查看每个 GCRootInfo 并找到类型,看看它是否是 Type.UNREACHABLE (2048) 然后才选择一个 GC 根,其中 GC 根信息表示无法访问。这将找到无法到达的对象根。Keep unreachable objects 只是将一些不可达对象标记为 GC 根 - 剩余的不可达对象由这些根保留。查询比方式更好。
SELECT OBJECTS s FROM OBJECTS ${snapshot}.@GCRoots s WHERE ((SELECT t FROM OBJECTS ${snapshot}.getGCRootInfo(s) t WHERE (t.@type = 2048)) != null)
通过查找不可达 GC 根保留的所有对象来查找所有不可达对象:
SELECT AS RETAINED SET OBJECTS s FROM OBJECTS ${snapshot}.@GCRoots s WHERE ((SELECT t FROM OBJECTS ${snapshot}.getGCRootInfo(s) t WHERE (t.@type = 2048)) != null)
查找所有 LocalCache$StrongAccessWriteEntry 对象
SELECT * FROM com.google.common.cache.LocalCache$StrongAccessWriteEntry r
查找同样在不可访问对象集中的所有 LocalCache$StrongAccessWriteEntry 对象。
SELECT * FROM com.google.common.cache.LocalCache$StrongAccessWriteEntry r where r in (SELECT AS RETAINED SET OBJECTS s FROM OBJECTS ${snapshot}.@GCRoots s WHERE ((SELECT t FROM OBJECTS ${snapshot}.getGCRootInfo(s) t WHERE (t.@type = 2048)) != null))
在Eclipse Memory Analyzer wiki中有更多关于编写查询的信息。