Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Memory usage of Strings

843798Jan 24 2003 — edited Feb 4 2003
Hi 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";
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 4 2003
Added on Jan 24 2003
13 comments
156 views