Overview of garbage collection

Garbage collection is the mechanism used in Java to deallocate unused memory. Essentially, when an object is created, memory space is allocated and dedicated to that object until it no longer has any references pointing to it. At that time, the system deallocates the memory. 

Java performs this garbage collection automatically for us, which can lead to a lack of attention to memory usage and poor programming practices in the area of memory management and system performance. Java's garbage collection is considered an automatic memory management schema because programmers do not have to designate objects as ready to be deallocated. The garbage collection runs on a low-priority thread and, as you will read later in this chapter, has variable execution cycles.

In our overview of garbage collection, we will look at the following concepts:

  • Object life cycle
  • Garbage collection algorithms
  • Garbage collection options
  • Java methods relevant to garbage collection

We will look at each of these concepts in the sections that follow.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset