javaheap-memoryvisualvm

What is leaking int arrays in my program?


I have Java program that, over about 16 hours, is slowly filling the heap with integer arrays that the GC is not getting rid of.

I only have VisualVM available to diagnose the problem, which is how I found that it's int[] that is filling the heap.

Any ideas how I can find the source of the int[] creation?

I'm new to using the profiler so maybe I missed that function but I've used it's heap dump, snapshot, and profiler to look at this and all it's telling me is that int[] is in high use.


Solution

  • In VisualVM you can find the references to objects. This should give you a clue about what part of your program that is leaking those int arrays.

    Instructions:

    1. Let your program run for a long time, so that there are many leaked int array instances on the heap for you to find.

    2. Make a heap dump in VisualVM: Main menu > Applications > Heap Dump. A heap dump tab should open.

    3. In the heap dump tab, click the Summary field and change it to Objects. A list of the types of heap objects should open.

    4. Expand the int[] entry to see a list of instances.

    5. Expand one of the instances.

    6. Expand the references entry.

    A list of fields with references to that int array instance will open. The information here might give you a clue.

    Repeat step 5-6 for different instances until you find one of the leaked arrays.

    The following image shows the references to an int array in a heap dump of my Eclipse.

    e

    In this example the int array instance was stored in the valueTable field of some internal Eclipse OffsetTable class, which in turn was used by a RegistryObjectManager.