Memory usage of Strings
843798Jan 24 2003 — edited Feb 4 2003Hi all
What happens with the memory usage in Java?
Primarly the handling of Strings I do not understand.
Following two classes, an object of the first neads 16 bytes (ok) but the second spends 88 - WHY? (... and it's not because the garbage collector was not running before I checkt the files...)
Can anybody explain this behaviour?
/**
* An Object neads 16 bytes.
*/
public class TestObject {
String str;
public TestObject(){
str = "blabla";
}
}
/**
* An Object neads 88 bytes.
*/
public class TestObject {
String str;
public TestObject(){
str = "bla";
str += "bla";
}
}