Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialized object size vs in memory object size in Java

Is there a way of estimating (roughly) in memory object size from Serialized object size in Java

like image 466
restrictedinfinity Avatar asked Aug 22 '11 11:08

restrictedinfinity


People also ask

Does serialization reduce size?

In some cases, the secondary intention of data serialization is to minimize the data's size which then reduces disk space or bandwidth requirements.

What is the advantage of object serialization in Java?

Serialization offers a plethora of benefits. Some of its primary advantages are: Used for marshaling (traveling the state of an object on the network) To persist or save an object's state.

Does serialization compress the data?

Compact serialization is also binary serialization but NCache provides a lot more flexibility with this serialization framework. Compact serialization does not reduce the size of the entire data, it instead only reduces the size of the data that is travelled over the network.

How much memory is allocated to an object in Java?

Minimum object size is 16 bytes for modern 64-bit JDK since the object has 12-byte header, padded to a multiple of 8 bytes. In 32-bit JDK, the overhead is 8 bytes, padded to a multiple of 4 bytes.


1 Answers

The size in memory will be usually between half and double the serializable size. The most extreme example might be the Byte which is more than 80 bytes Serialized can be 16 bytes in memory.

You can use a profiler to tell you how much memory an object uses. Another way is to use a tool based on Instrumentation.getObjectSize(object)

You might find this interesting Getting the size of an Object

like image 83
Peter Lawrey Avatar answered Oct 21 '22 14:10

Peter Lawrey