Memory usage of Java Strings and string-related objects
by, 04-26-2012 at 06:35 PM (469 Views)
Everywhere strings are present. It is quite difficult thing to write down an application that is not used by them or others use it extensively. Various typical applications like server entities that are obtained from databases, or data present to be displayed at web, most of the objects that have been stored on heap might be Strings. Therefore, when usage of memory is crucial it means that understanding of the Strings memory usage or the related objects is also crucial.
If your have command over using the C language or other and don’t know how to deal with Unicode then you might have an expectation that one byte per character be taken up essentially by a string plus one byte terminator. But for Java languages it doesn’t happen now days.
- Atleast eight bytes (of housekeeping data) of each object are present. Array of 12 bytes and they all will get padded to 16 bytes multiples.
- Actually, Java String may have one or more than 1 object;
- Few extra variables are present in a Java String that has not yet been considered.