…Understanding the Memory Usage of Your Application
- With 32 bit architectures, you’ll quickly run out of memory.
- java.lang.Integer is 4 times bigger than an 32-bit int and 9 times bigger than an 64-bit int.
- CompressedOpps reduces this overhead significantly and reduces the (non-native) Java heap size.
- For one java.lang.String, two objects are created. The overhead for one “word” are three “words” of extra overhead.
- A hashset is just a wrapper around a hashmap where the wrapper restricts the functionality.
- LinkedLists have a huge overhead because of the created entry object for every stored object. In general, check the default sizes for collections and buffers.
- HashMap, HashSet and StringBuffer will double its internal arrays if the size is exceeded.
- Lazy allocation of collections
- Don‘t create collections for a single object
- Correct sizing of collections
- Avoid expansion of such collections due to x2 algorithm
- Collections do not shrink once expanded
- Empty collections are a huge waste. Eclipse Memory Analyser Tool (MAT) can help to find them.
Chris Bailey – From Java Code to Java Heap