Pages

Showing posts with label Eclipse memory Analyzer. Show all posts
Showing posts with label Eclipse memory Analyzer. Show all posts

Monday, November 17, 2014

Eclipse Memory Analyzer: Shallow heap and Retained heap

Developers are more concerned about the size of objects when they are created. Eclipse memory analyzer gives us information about the size of the object in 2 calculations.

Shallow Heap
Retained Heap

Shallow heap is the memory consumed by one object. An object needs 32 or 64 bits (depending on the OS architecture) per reference, 4 bytes per Integer, 8 bytes per Long, etc. Depending on the heap dump format the size may be adjusted (e.g. aligned to 8, etc...) to model better the real consumption of the VM.

Shallow size of an object is the amount of allocated memory to store the object itself, not taking into account the referenced objects

Retained size of an object is its shallow size plus the shallow sizes of the objects that are accessible, directly or indirectly, only from this object. In other words, the retained size represents the amount of memory that will be freed by the garbage collector when this object is collected

Dead objects are shown only with shallow size, as they do not actually retain any other objects.

Generally speaking, shallow size of an object is its "flat" size in the heap whereas the retained size of the same object is the amount of heap memory that will be freed when the object is garbage collected.

For example the shallow size of an instance of java.lang.String will not include the memory needed for the underlying char[] where as retained size includes.
Read More

Eclipse Memory Analyzer: Finding Strings

Eclipse Memory analyzer provides various ways of analyzing String from the heap dump. We can get the details of the String using

1. Open the Histogram -> Right Click on “java.lang.String” and select the List Objects. We can get the size by sorting the retained Size ( the memory kept alive by Each String )

2. If we want to get the value that is holding by the String, we can get by selecting the String, right click and “Copy -> Value”. The full value is then copied to the clip Board.

3. We can also use a Query to get the details. Select OOL from the Menu as







Enter “SELECT s.count, toString(s) FROM java.lang.String s” to extract the count property of the strings.
Read More

Eclipse Memory Analyzer: Unreachable Objects

An Object becomes unreachable when they don’t have any inbound references or when they become unreachable from any other root.

By default unreachable objects are removed from the heap dump which parsing and will not appear in the class histogram. We can still see the unreachable objects in Eclipse Memory analyzer.
1. From the link on the Overview page
2. From the Query Browser via Java Basics --> Unreachable Objects Histogram
This histogram has no object graph behind it (since they don’t have any in bound references).
Read More

Find Local Variables in Eclipse Memory analyzer

Finding local variables from the heap dump generated is easy using eclipse memory analyzer. As we know the life of the local variable is very small but if the variable is alive during the time of heap generation, we can fine the local variable details using

1. Click on the objects options button from the actions bar  
2. Select “Java Basics” -> Thread Details. This will list the objects for Specific threads
 We can also click on the “Thread Overview and Stacks”
3. Once it displays all the threads details, Right click on a Thread and select
“List Objects” -> With Outing going references

4. Now we can see all the objects with outgoing references. We can then search for the <Java Local> inside the thread tree for the local variables.

We can see something like these







Read More