Recently I changed the method of saving the data of a certain program. Instead of writing to a text file, I serialized the data. Saved in text format, the data files are about 60 kb, and serialized, the file is about 90 kb. Serialized, it takes up more HD memory, which seems strange to me. I was thinking about how to make smaller files.
Serialized, the data is saved in ArrayLists. Would saving the data in arrays instead of ArrayLists save memory?
From what I understand, whenever two
String variables have the same value, the computer remembers the String only once, and remembers that those two references are references to the same object. Therefore, the memory taken up is the memory needed for the String, and for the two references to the String. Could it be that when serialized, two Strings are written to the file when there are two references, even if the references are references to the same String?
Are primitives, like int, remembered the same way as Strings? For example, if int a = 4 and int b = 4, does the computer remember the integer 4 once or twice?