Eclipse Memory Analyzer (MAT) is a powerful tool for heap dump analysis. It has several great features to debug memory problems effectively. ‘Incoming references’ and ‘outgoing references’ is one such feature. In this article let’s discuss about ‘incoming references’, ‘outgoing references’ and difference between them.
In Eclipse MAT, when you right click on any object you will see drop down menu. If you select ‘List Objects’ menu item, you will notice two options:
a. ‘with outgoing references’
b. ‘with incoming references’
As it’s easier to understand new concepts through examples, let’s learn ‘Incoming References’, ‘Outgoing References’ also through an example. Say suppose your application’s source code looks like this:
Now if we are going draw the objects diagrammatically for the above example application it’s going to look like this:
Fig: Sample application’s objects references
a. Object A and Object B are holding reference to Object C
b. Object C is holding reference to Object D and Object E
Now in this sample project let’s study the ‘Incoming references’ and ‘Outgoing references’ of object C.
Incoming References of object C All the objects that holds references object C is called ‘incoming references’. In this example, Object C’s incoming reference are object A, object B and class C.
To confirm this theory, we captured heap dump from the above sample application and uploaded to Eclipse MAT. Below are the ‘Incoming References’ reported by Eclipse MAT for Object C.
Fig: Incoming references of Object C
When you right click on Object C in the ‘Dominator Tree’ and select ‘List Objects > with incoming references’ option you will notice Eclipse MAT to generate above report. You can notice Object A, Object B and class C reported as incoming references. Eclipse MAT also displays the variables used to reference Object C. You can see object A referencing object C using the variable ‘c1’. Similarly, other variables used to reference object C are also reported.
Outgoing References of object C All the objects that Object C references is called ‘outgoing references’. In this example, Object C’s outgoing reference are object D, object E and class C.
Below is the ‘Outgoing References’ reported by Eclipse MAT for Object C.
Fig: Outgoing references of Object C
When you right click on Object C in the ‘Dominator Tree’ and select ‘List Objects > with outgoing references’ option you will notice Eclipse MAT to generate above report. You can notice Object D, Object E and class C reported as incoming references. Eclipse MAT also displays the variables by Object C to reference other objects. You can see object C referencing object D using the variable ‘d1’. Similarly, other variables used in object C are also reported.
We hope this article might have clarified the difference between ‘Incoming references’ and ‘Outgoing references’. To learn about the difference between ‘Shallow Heap’ and ‘Retained Heap’, you may refer to this article
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
Devious Experiments for a Truly Passive Greenhouse!