Monday, December 29, 2008

Information on memory usage of objects

The section on Java memory usage now contains the following additional articles:
  • information on how to calculate the memory usage of a Java object in general, considering the memory used for "housekeeping" by the JVM
  • calculating the memory usage of Strings, which can often the type of object to use up the biggest proportion of space in a Java application: this section actually considers the memory use of string-related objects such as StringBuffers and StringBuilders
A section on reducing the memory taken up by Strings looks at string canonicalisation, a fairly standard approach (but one which requires certain caveats), plus introduces the example of a CompactCharSequence class, that stores strings as 1 byte per character, thus taking up around half othe memory taken up by a regular Java String (at the expense of not supporting Unicode).

Comments on these articles welcome as usual.

1 comment:

Markus Kohler said...

Great stuff!
Do you already know the Eclipse Memory Analyzer?
Check http://www.eclipse.org/mat

We have special support for finding duplicates of Strings.

Regards,
Markus