Garbage Collection
Because objects are dynamically allocated through using the new operator, you may be wondering how this type of objects is destroyed and their memory released for later reallocation. Within some languages, like as C++, dynamically allocated objects must be manually released through use of a delete operator. Java takes a various approach; it handles reallocation for you automatically. The method which accomplishes this is known as garbage collection. That works like this: when no references to an object exist, that object is supposed to be no longer required, and the memory occupied through the object could be reclaimed. There is no explicit requirement to destroy objects as in C++. A Garbage collection just occurs sporadically during the execution of your program. It will not occur simply since one or more objects exist which are no longer used. In addition, various Java run-time implementations will take varying approaches to garbage collections, but for the most part, you should not have to think about it although writing your programs.