I read about tuning Java performance and came across this.
When we run
public class test { public static void main(String a[]){ for(int i=0;i<1000000;i++){ for(int j=0;j<100000;j++){ Double d = new Double(1.0); } } } }
JVisualVM displays a graph of memory consumption:

But when we run the code below,
public class test { public static void main(String a[]){ for(int i=0;i<1000000;i++){ for(int j=0;j<100000;j++){ } } } }
JVisualVM displays a sawtooth shape:

Why is this happening? How and why does the gc launch restriction change for both cases?
source share