Skip to content

How to build Agrona maps that can be viewed in a debugger

Problem

When you debug a process containing Agrona maps, and you need to debug them you find that your debugger is not correctly displaying the contents.

Solution

When constructing the Agrona map use a constructor that allows setting shouldAvoidAllocation to false.

Sample

1
Int2ObjectHashMap<String> noAlloc = new Int2ObjectHashMap(100, 0.55f, false);

shouldAvoidAllocation is the last parameter to the Int2ObjectHashMap hash map.

Discussion

Agrona will cache iterators and map entries unless shouldAvoidAllocation is false. This is typically the norm for how Agrona is used in systems, with debugging being the only time a developer typically bumps into this problem. If you need to iterate through the key or entry set, consider if HashMaps are the correct structure for your usage.

See Also