I am analysing a very large heap to find opportunities to save memory. MAT shows me a large object (call it level A, retained size 27MB), but the retained sizes of the immediately referenced objects (call them level B) do not add up to anything like this amount (they add up to just 12MB)

I presume the 'missing' 15MB is being consumed by objects (call them level C) that are referenced (directly or indirectly) by more than one of the level B objects; if they are not uniquely 'owned' by a level B object they will not contribute to its retained size.

Is there any technique for analysing the retained heap of the large level A object so that I can identify these level C objects and work out where all the memory is going?

I could do with being able to restrict the focus of all MAT's functions to just the subset of the heap retained by the level A object. Without being able to focus on that retained heap, all my level C objects get lost in a sea of similar objects from other parts of the heap.

You are correct that the retained heap for an object comprises those objects which would be eligible for garbage collection if that object itself were collected. Therefore your "level C" objects which are referenced by more than one "level B" object are not part of the retained heap for the level B objects.

A view which might assist you is the Dominator Tree, which is a transformation of the object graph such that the descendants of an object (children and 'grandchildren' etc) represent the full retained set of the object. This will allow you to see your level C objects as children of your level A object.

There is a helpful definition of the Dominator Tree and further explanation in the Memory Analyzer help panels.

Another technique to find the level C objects is to list objects with outgoing references (right-click on the level A object); this allows you to navigate along the outgoing references from object A until you reach the level C objects, assuming you follow the appropriate reference links.

Usually I would also use the Dominator Tree, as Lawrence already mentioned. You can show also single objects (or a small selection of objects) in the dominator tree using the context menu "Java Basics" -> "Open in Dominator Tree".

It may be also useful to have a "flat" view on all objects which build the size, i.e. the retained set. To do this use the context menu on your big object and say "Show Retained Set". You get a list of all the objects grouped by class.

Additionally you could try if our more suffisticated memory-footprint analysis will give you some useful hints or not. Just select your object and call from the context menu "Leak Identification" -> "Component Report". The command names are probably a bit misleading, but this report should give you some overview of the retained objects. You could call this for all ojbects in your packages togeter.

It turns out that I have very large numbers of the same types of object. The ones that are only referenced once show up nicely in the first view as below a certain level B hash table, but the ones that are referenced more than once do not. But these multiply referenced objects can be seen easily in the dominator view found via the mouse menu on the original level A object... which means I can tell what classes they are and why they have been generated.