
You know what makes java great ? the precious garbage collector .
Know apart from being my secret crush and making our life easier . The garbage collector is located in the jvm (java virtual machine) what a lovely place to be. this program runs automatically.

It will look at the heap memory , and if it find any unused objects that we will not use anymore it will delete them from the memory for us.
Your not falling in love yet ?
Ok , let’s see how good we have it .
In C/C++, programmer is responsible for both creation and destruction of objects. Usually programmer neglects destruction of useless objects. Due to this negligence, at certain point, for creation of new objects, sufficient memory may not be available and entire program will terminate abnormally causing OutOfMemoryErrors.
boy am I glad I use java am I right ?
Citations : https://www.geeksforgeeks.org/garbage-collection-java/