top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find out how much memory is used by an object in Java?

+2 votes
301 views

Java does not have sizeof operator now my question is How to find out how much memory is used by an object in Java?

posted Apr 15, 2016 by Madhavi Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

You can use the java.lang.instrumentation package.Here is details of this package:
http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html

It has a method that can be used to get the implementation specific approximation of object size, as well as overhead associated with the object and follow this link to get a suitable program for your requirement.

http://stackoverflow.com/questions/9368764/calculate-size-of-object-in-java

answer Apr 16, 2016 by Shivam Kumar Pandey
...