Is Java serialization a tool to shrink the memory footprint?

No... serialization is a way to write or read a representation of an object's state as a byte array. It is not an alternative in-memory representation. An object's serialized form may or may not consume more bytes than it does inside the JVM; typically it would be quite comparable. In rare cases it could be more, and sometimes an object's state can be completely serialized in a way that consumes fewer bytes than it does on the heap. But no to answer the question it is not a "tool to shrink memory footprint".


My question is, whether it is a good tool to decrease the memory usage.

No it is not a good tool for doing that. The serialized object representation includes a lot of 'metadata' that describes the type and representation of the object. Unless you serialize a significant number of objects into one 'stream', the 'metadata' overhead will make the serialized form larger than the original form. Ignoring this overhead, the serialized representation is typically more compact, but the saving will depend to a considerable extent on the object's representation types. (Take a look at the "Object Serialization Stream Protocol" for more details.)

And as other answers mention, you temporarily increase memory usage while serializing and deserializing because you have to hold both the serial and object representations AND the map used for dealing with cycles, etc.

If you want to represent a data structure in a compact form in memory, you would be better off developing your own application-specific serialization scheme. But IMO, it would be better still to write the data to the file system or a database.


The only way it could shrink memory footprint is by serializing some object with transient fields, dumping the original objects and deserializing - this way you lost objects in transient fields.