Bug 470369

Summary: Better support of WeakHashMap in dominator tree/retained set
Product: [Tools] MAT Reporter: Vladimir Sitnikov <sitnikov.vladimir>
Component: CoreAssignee: Project Inbox <mat.core-inbox>
Status: CLOSED MOVED QA Contact:
Severity: normal    
Priority: P3    
Version: 1.4   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Vladimir Sitnikov CLA 2015-06-17 08:51:40 EDT
Currently MAT does not recognize the fact that "WeakHashMap" is not the only dominator of the values that are stored in the map.

In other words, it might realize that if all strong reference to the key are gone, the value would go away.

It makes sense to support that in calculation of dominator tree.
Additional support might be needed for some well-known weak/soft collections.
Comment 1 Andrew Johnson CLA 2020-02-27 06:10:27 EST
The Java Basics > References > Weak Reference Statistics query can help as one of the result tables is 'Only Weakly Retained'.

You could get a list of all the objects which were not 'Only Weakly Retained' by:
adding a histogram of all the objects to the compare basket,
add the 'Only Weakly Retained' objects to the compare basket, 
select both, 
do a 'Compare Tables with all set operations', 
select all the objects and do 'Table 1 without table 2' > 'Java Basics' > 'Show As Histogram'.

You could then have a new heap dump with just those objects:
select all the objects in that Histogram,
'Export Snapshot'

then reopen the resulting dump.

There are still a couple of problems:
1. The objects in the new heap dump will have some dangling references to the weakly retained objects. These won't show on the outbound/inbound expansion, but will show on the object inspector and might break some queries.
2. The compare tables query can loss table rows if there are two identically named rows in the source e.g. if in a histogram a class is loaded
twice by two class loaders. This could result in some missing objects in the compare table and resulting outputs.
Comment 2 Eclipse Webmaster CLA 2024-05-08 14:49:17 EDT
This issue has been migrated to https://github.com/eclipse-mat/org.eclipse.mat/issues/23.