Dhruv
Dhruv

Reputation: 10693

jProfiler Live Memory All object view

I have created following simple program just to observe the object and memory information when I create list of String in java.

import java.util.ArrayList; import java.util.List;

public class Main {

    public static void main(String[] args) {

        List<String> strObj = new ArrayList<String>();

        for (int i = 0; i < 1000; i++) {
            strObj.add("abc");
        }
    }
}

But jProfiler shows me following information in Live Memory -> All Object view which I am not able to understand.

How so many char[] instance are created? I have created only 1000 String object, how around 9000 were created?

Kindly help me out interpreting this profiler information.

enter image description here

Upvotes: 1

Views: 1308

Answers (1)

Ingo Kegel
Ingo Kegel

Reputation: 48025

The dynamic memory views cannot answer this question. You have to go to the heap walker and select all char[] instances. Then look at the "Cumulated incoming references" view to analyze how the instances are referenced.

You can also switch on allocation recording at startup with an appropriate recording profile, then you can see where they were allocated.

Upvotes: 1

Related Questions