After deserialization program occupies about 66% more RAM
My program stores in RAM dictionary with about 100'000 words. This
dictionary occupies about 380MB of RAM. But when I serialize that dictionary
and then deserialize the program occupies about 620MB. Dictionary is the
only variable to which program has reference in the moment of serialization
and after deserialization.
Deserialization works correctly i.e. after deserialization I obtain the same
object of dictionary as I had before serialization (I can check it because I
can store dictionaries to text files and compare them - files representing
dictionaries before and after serialization are the same).
After deserialization I close stream which I used to read dictionary object
from file and run garbage collection.
Here are methods which I use to serialize and deserialize:
------------------------------------
public class Dictionary implements Serializable {
...
public void serializeTo(String fileName) throws IOException {
ObjectOutputStream out = new ObjectOutputStream(new
FileOutputStream(fileName));
out.writeObject(this);
out.close();
}
public static Dictionary deserializeFrom(String fileName) throws
IOException, ClassNotFoundException {
ObjectInputStream in = new ObjectInputStream(new
FileInputStream(fileName));
Dictionary dictionary = (Dictionary)in.readObject();
//collator hasn't been serialized to file, so we must recreate it
manually
dictionary.collator = Collator.getInstance(dictionary.getLocale());
in.close();
System.gc();
return dictionary;
}
}
------------------------------------
Anybody knows what can I do to decrease the amount of memory used after
deserialization?
Thanks for any hints.