I analysed simple heap dump from Java program containing only this in main method.
public static void main(String[] args) throws IOException {
System.in.read();
}
Using HPROF parser library, my output is that:
Done, found:
Classes: 473
Instances: 13161
Namespace java
Classes: 251
Instances: 9033
How is that possible that there are so many instances without me creating any of them. Are these java runtime instances?
The JVM starts execution of Java bytecode long before entering application's main method. The significant part of the JVM bootstrap procedure is written in Java. In particular, this includes:
This initialization code, having been written in Java, sometimes allocates Java objects, of course. And some of these objects stay alive for the entire lifespan of the JVM.
This answer describes an approach to find out, what these objects are, and where they are allocated.
Here is a clickable Flame Graph of objects allocated during the JVM bootstrap:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With