How much space does an object takes from the memory heap? How can this be done?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is far more complex than just using free memory computations (which don’t take into consideration garbage collections and new allocations by other threads). Take a look at:
http://www.javaspecialists.eu/archive/Issue142.html
This is advanced stuff, however.
–EDIT–
The solution above finds the deep size of an object (using a stack to traverse the reference network, a collection of visited references, and of course instrumentation).
However, getting the shallow size of an object is simpler, and can be achieved by java 1.5 instrumentation without extra work (see Instrumentation.getObjectSize()).