Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Memory Analyzer » How to analyse retained heap(MAT shows retained heap sizes for objects, but how can one analyse the contributors to that retained heap?)
How to analyse retained heap [message #665305] Thu, 14 April 2011 08:59 Go to next message
Richard Hutchings is currently offline Richard HutchingsFriend
Messages: 2
Registered: April 2011
Junior Member
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.
Re: How to analyse retained heap [message #665312 is a reply to message #665305] Thu, 14 April 2011 09:56 Go to previous messageGo to next message
Jonathan Lawrence is currently offline Jonathan LawrenceFriend
Messages: 16
Registered: July 2009
Junior Member
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.
Re: How to analyse retained heap [message #665318 is a reply to message #665312] Thu, 14 April 2011 10:26 Go to previous messageGo to next message
Krum Tsvetkov is currently offline Krum TsvetkovFriend
Messages: 161
Registered: July 2009
Senior Member
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.

I hope this helps.
Re: How to analyse retained heap [message #665322 is a reply to message #665318] Thu, 14 April 2011 10:31 Go to previous message
Richard Hutchings is currently offline Richard HutchingsFriend
Messages: 2
Registered: April 2011
Junior Member
Many thanks both - that is just what I wanted.

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.

I haven't looked at the leak report yet, but I'm now very happy!
Previous Topic:JVM terminates with Exit code -1
Next Topic:Unable to figure out HashMap values - (use of Hash Entries context menu)
Goto Forum:

Current Time: Mon Nov 19 23:45:09 GMT 2018

Powered by FUDForum. Page generated in 0.01695 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top