Tutorial 13 : Garbage Collection


In java, garbage means unreferenced objects.
Garbage Collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to destroy the unused objects.
To do so, we were using free() function in C language and delete() in C++. But, in java it is performed automatically. So, java provides better memory management.

Advantage of Garbage Collection

  • It makes java memory efficient because garbage collector removes the unreferenced objects from heap memory.
  • It is automatically done by the garbage collector(a part of JVM) so we don't need to make extra efforts.

How can an object be unreferenced?

There are many ways:
  • By nulling the reference
  • By assigning a reference to another
  • By annonymous object etc.
Share on Google Plus

About Yomal Malinda

    Blogger Comment
    Facebook Comment

1 comments:

We value your comments... Whether it is Good or Bad they are the only thing which we can get from you guys...! :) :) Please be kind enough to stop by and comment something about this post....!

Powered by Blogger.