Incoming and outgoing references in Eclipse MAT

Share
  • March 15, 2019

Eclipse Memory Analyzer (MAT) is a powerful tool for heap dump analysis. It has several great features to debug memory problems effectively. One such feature is the incoming references and outgoing references. In this article, let’s discuss why they are so helpful and the differences between an ‘incoming’ and ‘outgoing’ reference.

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: with outgoing references and with incoming references.

Since it’s easier to learn through examples, here’s a good one to help differentiate them. Say your application’s source code looks like this:

publicclass A {

	private C c1 = C.getInstance();
}

publicclass B {

	private C c2 = C.getInstance();	
}

publicclass C {

	privatestatic C myC = newC();

	publicstatic C getInstance() {
		returnmyC;
	}

	private D d1 = newD();
	
	private E e1 = newE();	

}

publicclass D {

}

publicclass E {

}

publicclassSimpleExample {

	publicstaticvoid main (String argsp[]) throws Exception {
	
		A a = newA();
		B b = newB();
	}
} 

Now, if we are going draw the objects diagrammatically for the example above, it’s going to look like this:

Eclipse MAT

Sample application’s objects references

We can see from this diagram that:

  • Object A and Object B are holding reference to Object C
  • Object C is holding reference to Object D and Object E

So, let’s study the incoming references and outgoing references of object C in this sample project.

SEE ALSO: Shallow heap and retained heap calculation in Eclipse MAT

Incoming references for Object C

All the objects that holds references object C are 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 it to Eclipse MAT. Here are the incoming references reported by Eclipse MAT for Object C.

Eclispe MAT

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 are all 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.

SEE ALSO: GCeasy API – Time Filters: Garbage collection analysis made simple

Outgoing references of Object C

All the objects that Object C references are called outgoing references. In this example, Object C’s outgoing reference are Object D, Object E and Class C.

Here are the ‘Outgoing References’ reported by Eclipse MAT for Object C.

Eclipse MAT

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 generates the above report. You can notice Object D, Object E and Class C are all 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.

SEE ALSO: StackOverFlowError: Causes & solutions

In conclusion

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 should refer to this article.

The post Incoming and outgoing references in Eclipse MAT appeared first on JAXenter.

Source : JAXenter