String[] stringArray = new String[] { "abc", "xyz" };
Executing this line there are two String literals created “abc” and “xyz” in PERMGEN space. Since the initialization has a new operator I am not sure if there’s any memory allocated on HEAP.
Thanks guys.
All objects, except string literals, are created on the heap. From Java 7, string literals are created on the heap as well.
In theory, escape analysis can prevent
newobject from being created on the heap and perhaps using the stack instead. This rarely happens in practice AFAIK.In answer to EJP question, I haven’t fund a non trivial example but
From http://www.oracle.com/technetwork/server-storage/ts-7392-159315.pdf page 22
In theory this feature has been there for some time, but it didn’t work particularly often (even find a contrived example was hard) In Java 7, finding contrived examples is easier. 😉
prints when run with -XX:-UseTLAB
if you add
-XX:-DoEscapeAnalysiswhich is not the default