I am puzzled by the "number of objects" (column Objects) shown in the "Merged paths" view. It doesn't add up with the really existing number of objects in a memory snapshot.
An example:
Code: Select all
Class list
+-----------------------+--------------+----------------+-------------------+
| Class | Objects | Shallow Size | Retained Size |
+-----------------------+--------------+----------------+-------------------+
| test.MemoryTest$A[] | 1 0 % | 32 0 % | 4'704 0 % |
| test.MemoryTest$A | 4 0 % | 96 0 % | ~ 4'480 0 % |
| test.MemoryTest$B[] | 4 0 % | 224 0 % | ~ 4'384 0 % |
| test.MemoryTest$B | 40 0 % | 960 0 % | ~ 4'160 0 % |
| test.MemoryTest$C[] | 40 0 % | 1'280 0 % | ~ 3'200 0 % |
| test.MemoryTest$C | 120 0 % | 1'920 0 % | ~ 1'920 0 % |
| test.MemoryTest | 1 0 % | 16 0 % | 16 0 % |
+-----------------------+--------------+----------------+-------------------+
Code: Select all
Merged paths
+---------------------------------------------------------------+--------------+-----------------+
| Name | Objects | Retained Size |
+---------------------------------------------------------------+--------------+-----------------+
| +---<All the objects> | 120 100 % | 1'920 100 % |
| | | | |
| +---test.MemoryTest$C[] | 120 100 % | 1'920 100 % |
| | | | |
| +---test.MemoryTest$B | 120 100 % | 1'920 100 % |
| | | | |
| +---test.MemoryTest$B[] | 120 100 % | 1'920 100 % |
| | | | |
| +---test.MemoryTest$A | 120 100 % | 1'920 100 % |
| | | | |
| +---test.MemoryTest$A[] | 120 100 % | 1'920 100 % |
| | | | |
| +---statics or constant pool of test.MemoryTest | 120 100 % | 1'920 100 % |
+---------------------------------------------------------------+--------------+-----------------+
The example code used to generate the objects seen in the snapshot:
Code: Select all
package test;
import org.junit.Test;
public class MemoryTest {
public static class A {
public int id;
public B[] b;
}
public static class B {
public int id;
public C[] c;
}
public static class C {
public int id;
}
private static A[] as;
@Test
public void test() throws Exception {
as = new A[4];
for (int a = 0; a < as.length; a++) {
as[a] = new A();
as[a].id = a;
as[a].b = new B[10];
for (int b = 0; b < as[a].b.length; b++) {
as[a].b[b] = new B();
as[a].b[b].id = b;
as[a].b[b].c = new C[3];
for (int c = 0; c < as[a].b[b].c.length; c++) {
as[a].b[b].c[c] = new C();
as[a].b[b].c[c].id = c;
}
}
}
System.out.println("Now take a snapshot while waiting...");
Thread.sleep(50 * 1000);
System.out.println("*Bye");
}
}
Cheers,
Matthias