How can I find out the size of a Java object?

John Mitchell

In terms of the run-time, in-memory size of a Java object... you can't. Why? Because that's something that is totally implementation dependent. Different JRE's are allowed all of that leeway so that they can be implemented in a wide variety of ways that can take into account e.g., local issues. This is quite unlike languages like C/C++ where things are much more closely tied to the underlying hardware model -- the Java programming language is just tied to the Java Virtual Machine model.

In terms of serialized objects, check out How can I determine the byte length of an object that I serialize to a stream?