Eclipse MAT — Incoming, Outgoing References

Check out the differences between incoming and outgoing references in Eclipse MAT.

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’ are one such feature. In this article, let’s discuss incoming references, outgoing references, and the 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:

  • with outgoing references
  • with incoming references

As it’s easier to understand new concepts through examples. Let’s learn more about incoming references and outgoing references through an example. Say your application’s source code looks like this:

public class A {
     private C c1 = C.getInstance();
}
public class B {
     private C c2 = C.getInstance();
}
public class C {
     private static C myC = new C();
     public static C getInstance() {
             return myC;
     }
     private D d1 = new D();
     private E e1 = new E();
}
public class D {
}
public class E {
}
public class SimpleExample {
     public static void main (String argsp[]) throws Exception {
            A a = new A();
            B b = new B();
     }
}

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
  • Object A and Object B are holding a reference to Object C
  • Object C is holding a reference to Object D and Object E

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

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注