arcy
arcy

Reputation: 13133

want to look at memory used by one Java object in eclipse

I have a java project written in eclipse (RAD, actually); it uses a significant amount of memory by virtue of using iText. I am looking at using a different way of generating my iText document that is supposed to use less memory. I want to know how much less memory it uses.

I know what object will be the root for the largest portion of the memory; it would be fine for my purposes if I could set a breakpoint and then do something that would tell me the deep-copy memory used starting with that object (i.e., the memory used by it and all of its direct and indirect references).

I've been looking at memory monitors and heap dump analyzers and so forth for an hour now, and am pretty confused. All of them appear to be pointed at answering a different problem, or at least pointed to such a general class of problems that, even if I could get them installed and working, it is not clear whether they would answer MY question.

Can someone point me to a reasonably simple way to answer this limited question? I figure if I run the code once the current way, find out the memory used by this object and maybe one or two others, then run it again and look at the same values, I'll know how much good the new technique is doing.

rc

Upvotes: 1

Views: 763

Answers (2)

PhiLho
PhiLho

Reputation: 41152

You can fire up JVisualVM, shipped with all Oracle JDK and available independently.

Monitor your process, and at some point, you can do a Heap Dump. In the heapdump tab, you can go to the OQL console and select your object[s]. When viewing the instance of an object, you can request to compute the retained size. That will give you the total size of your object.

Upvotes: 0

Franz Ebner
Franz Ebner

Reputation: 5106

http://www.eclipse.org/mat/

works great for me... tutorials are included

Upvotes: 1

Related Questions