Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Eclipse, when debugging, is there an easy way to see a variable's total memory size?

Tags:

From the Debug view, when looking at the Variables tab, is there a way to easily see how much of the heap a given variable is consuming? (Something akin to Java's Heap Analysis Tool)

like image 325
Aaron Fi Avatar asked Jan 24 '11 18:01

Aaron Fi


People also ask

How do I see memory in Eclipse?

Fields. In the Debug Perspective of ED Eclipse, you can open the Memory View by selecting Window > Show View > Other > Debug > Memory.

How can check variable value while debugging in Eclipse?

Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show its value. You can also add a permanent watch on an expression/variable that will then be shown in the Expressions view when debugging is on.

How do I get debug view in Eclipse?

If Eclipse does not automatically switch to the Debug perspective, you can locate it manually in the Window entry on the menu bar or by clicking the Choose Perspective button (a button with a plus on it) in the upper right corner of the Eclipse window under the menu bar line.

What is heap size in Eclipse?

Heap starts at 50 MB and grows to the default maximum. Heap starts at default initial value and grows to a maximum of 256 MB.


2 Answers

I think this will help:

Memory Analyzer (MAT)

The Eclipse Memory Analyzer is a fast and feature-rich Java heap analyzer that helps you find memory leaks and reduce memory consumption.

Use the Memory Analyzer to analyze productive heap dumps with hundreds of millions of objects, quickly calculate the retained sizes of objects, see who is preventing the Garbage Collector from collecting objects, run a report to automatically extract leak suspects.

like image 146
Naveed Avatar answered Oct 11 '22 13:10

Naveed


A half-measure would be to watch for changes in the total RunTime's used ram with something like:

Runtime rt = Runtime.getRuntime(); long currInUse = rt.totalMemory() - rt.freeMemory();

like image 36
Fletch F Fletch Avatar answered Oct 11 '22 12:10

Fletch F Fletch