fast-serialization icon indicating copy to clipboard operation
fast-serialization copied to clipboard

Serializing doubles memory usage on Android

Open xbit opened this issue 7 years ago • 1 comments

When trying to serialize a complicated Object that has a huge HashMap the memory usage is doubled. The memory goes from 200MB to about 405MB. I'm serializing it this way:

FileOutputStream fileOut = ....
FSTObjectOutput  objectOut = new FSTObjectOutput(fileOut);
objectOut.writeObject(object, SerializableObject.class);
....
objectOut.close();

Is there a way to lower memory usage when serializing? Or am I doing something wrong?

xbit avatar Feb 14 '18 05:02 xbit

fst allocates a byte array buffering at least the complete output of a stream for performance reasons. As its a single object, it has practically no drawback on GC duration, however there still is a peak in mem consumption.

In order split this. one could write key, values of a hashmap using FSTConfiguration.asByteArray(..) and write those to an ordinary ouput stream, however object link restoration (links to same objects) won't work this way.

RuedigerMoeller avatar Feb 15 '18 11:02 RuedigerMoeller