A single conversation with a wise man is better than ten years of study.
~ Chinese Proverb ~

How much memory do your objects really need?

Nikita Salnikov-Tarnovski

Download slides

Java collections framework is probably the most frequently used Java API. Rarely an algorithm is implemented without using some class from it. But do you really know how much memory that three-element set uses? In this talk we will describe hands-on how memory (in)efficient Java Collection classes are and discuss alternatives to using them.

We will begin by discussing some ways of measuring the memory consumption of different objects and object graphs in Java applications. Next, these techniques will be used to measure how much memory simple objects actually take. While at it, we will explain and discuss object references, memory alignments, integer cache and flyweight objects.

After the discussion of simple objects we will then demonstrate how much memory is really needed in order to accommodate a given amount of data into different structures from Java Collection API.

In the end of the talk we briefly discuss some alternatives to Java Collections, such as Google Guava and Trove and their memory footprint in comparison to standard libraries.

More talks