Garbage Collection

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Garbage Collection as PDF for free.

More details

  • Words: 167
  • Pages: 1
Garbage Collection

Chapter

4

Garbage Collection One of the biggest challenge before application developer is allocation and deallocation of memory resources. If it was not properly done, leads to memory leakage and result are unpredictable. Java has built-in facility to re-claim unwanted memory; this is known as garbage collection. Garbage collector plays its role if there is any memory deficiency. Usually an object no longer referenced, for example when you assign with null, it could be ready for garbage collection. In java all objects are created in heap memory, whereas primitive type and object reference are place in stack memory. Object class has defined finalize() method that is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. The below is program example. class MyGC{ public static void main(String args[]){ MyObject mo1 = new MyObject(); mo1=null; System.gc(); } } class MyObject{ public MyObject(){ }

System.out.println("Object created");

protected void finalize(){ System.out.println("Garbage collector in action");

} }

tURBOPLUS

Related Documents

Garbage Collection
November 2019 17
Garbage Collection
June 2020 9
Garbage Collection
June 2020 11
Garbage Collection
November 2019 24
Garbage Collection
October 2019 20