Re: After deserialization program occupies about 66% more RAM
Robert Klemme wrote:
On 19.09.2006 14:32, Paul Davis wrote:
Changing the code to actually show the internal reference shows that
the deserialized version produces the same results as the one before
serialization.
What exactly do you mean by "same results"? Of course string values
I apologize for being unclear, by same results, I meant that:
System.out.println(a1 == a2);
for (int i = 0; i < a1.length; ++i)
{
System.out.println(i + ": " + (a1[i] == a2[i]));
}
produced the same output as:
System.out.println(c1 == c2);
for (int i = 0; i < c1.length; ++i)
{
System.out.println(i + ": " + (c1[i] == c2[i]));
}
meaning that there is no difference between the original values and the
deserialized ones.
remain the same. I was talking about internal representation (i.e. the
char arrays used). You cannot see that with a Java program alone, you
The intern() method returns a reference to the internal reference used
by the string object (according to the javadoc anyway).
need a memory profiler or a debugger to actually see those instances and
determine which are identical and which not.
Also, using String.intern() completely changes the semantics memory
wise. Of course the comparison returns true because it is actually the
same instance (and thus also the same char[] internally). My point was
that if strings are constructed from each other then serializing and
deserializing can seriously affect memory usage because of the changed
internal representation (no more sharing of char[]).
Using intern() might also be a bad idea for changing data because
interned strings will continuously increase the VM's memory. This might
not be an issue for short lived applications but it certainly can be for
long running apps.
I agree the intern() method should probably never be used. I was using
it here to demonstrate that the objects were pointing to the same
reference internally.
Regards
robert
Please forgive but, I don't understand what the example is trying to
demonstrate when the tests performed on the deserialized objects
produce the same output as the tests on the original objects.
false
0: true
1: false
-----------------------------------
false
0: true
1: false