Is there a way to find how much memory is used for a particular object? For example a List. Taking everything into account, like string interning and whatever is done by compiler/runtime environment/whatever.
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.
You’d really have to define exactly what you meant by ‘how much memory is used for a particular object’. For instance, you could mean ‘if this object were garbage collected, how much would be freed’ – or you could mean ‘how much memory does this object and everything it touches take up.’
Your point about string interning is a good example. Suppose you do:
Does
nonInternedStringsreally take up more memory thaninternedStrings? IfinternedStringswere garbage collected, it wouldn’t free as much memory – but ifinternedStringshad never been created (including not interning each of its elements) then more memory would never have been required.If you can be more specific about exactly what you mean, we may be able to help you. It’s a complex issue though.