How a garbage collector works of Java Language If you come from a programming language where allocating objects on the heap is expensive, you may naturally assume that Java’s scheme of allocating everything (except primitives) on the heap is also expensive
However, it turns out that the garbage collector can have a significant impact on increasing the speed of object creation
This might sound a bit odd at first—that storage release affects storage allocation-but it’s the way some JVMs work, and it means that allocating storage for heap objects in Java can be nearly as fast as creating storage on the stack in other languages
For example, you can think of the C++ heap as a yard where each stakes out its own piece of turf object
This real estate can become abandoned sometime later and mus