lRemember the problems of returning local objects in C++ where the lifetime has ended?
We dont
have this type of problem in Java because objects created with new exist for as long as we need them and we dont
have to worry about destroying
them
Java has
a garbage collector, which looks at all of the objects created with new and determines which ones are not being
referenced anymore then it can release
the memory for those objects at that point
so the memory can be used for new objects.
Please
keep in mind that although the garbage collector can release the memory when no more references point to the memory,
it may not if the memory is not
needed elsewhere
On the
other hand, this means that you never need to worry about reclaiming memory yourself
Simply
create objects, and when you no longer need them they will go away by themselves whenever necessary
There are no memory leaks!