3

I'm using jProfiler. I have objects of a class X. This class has many properties of type String, Integer and other class types. I want to know how much memory is being consumed by a single object of class X.

When I use jProfile to find memory usage, I only get size of an object of type X. I'm assuming, jProfiler is not showing memory used by its member variables. For example, a String property of class X is contributing to the total memory used by String.

I want to figure out total memory usage of the class X including memory used by all its property objects. Any information on how to achieve that using jProfile or some other tool/code?

Thanks in advance!

King J
  • 165
  • 2
  • 10
  • 2
    Don't see how this is a duplicate question, this was about how to do it with JProfiler which is perfectly capable of doing so. In the heap walker, create an object set with the selected object and click on "Calculate retained and deep sizes" in the header. The deep size is was you're looking for. Retained sizes are shown directly in the references view, but they only show how much memory would be freed if this object were to be removed. – Ingo Kegel Apr 09 '13 at 20:25

2 Answers2

2

Take a look at this http://www.javamex.com/tutorials/memory/object_memory_usage.shtml. It contains info about how to calculate Java objects memory usage as well as references to the tools to calculate it.

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
2

This is a very good tool that shows you the total memory used by an object

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

It will not only show you the memory it uses itself, but how much memory remains active due to the references it has.

EdH
  • 4,918
  • 4
  • 24
  • 34
  • Thanks for your answer. I tried integrating it with Eclipse and acquiring a heap dump.. but failed. Can you tell how to use this tool a bit? Thanks – King J Apr 09 '13 at 06:55
  • It's a stand-alone tool. Just download it and run it on it's own. You don't run it as a plugin or addon to Eclipse. Run it and open a head dump file in it – EdH Apr 09 '13 at 11:22
  • I'm sure their doco is more thorough than anything I put here: http://wiki.eclipse.org/index.php/MemoryAnalyzer – EdH Apr 09 '13 at 11:23