Java Garbage Collection Basics

Java Fundamentals Series – Day 5 Garbage Collection in Java : In Java, developers do not need to manually free memory. JVM automatically manages memory using Garbage Collection (GC). The Garbage Collector is an Mechanism were default implemented inside JVM which is Invoke automatically In java there has a method gC() which is present inside the System Class this gC() method is a static method so there is no need for object to invoke this method so we can able to access this particular method by the class name *** System.gC() ***. By help of this method we just provide the request to JVM to call the ** Garbage Collector ** but we cannot assure that it may or may not be call the GC . It is totally depends on JVM here we just provide request. What is Garbage Collection? Garbage Collection is the process of automatically removing unused objects from Heap memory. Why GC is Important? 1 Prevents memory leaks 2 Frees unused memory 3 Improves application performance How GC Works? 1 JVM identifies objects that are no longer referenced 2 These objects become eligible for garbage collection 3 GC reclaims the memory occupied by them 4 It removes the memory for anonymous. object Method : void finalize(): Incase we needed to do some set of work before GC get Called in that particular time we can use this finalize () this method is defined as protected for example - closing the file this like operation.we can able to provide inside this finalize() method #Java #GarbageCollection #JVM #BackendDeveloper #Placements

To view or add a comment, sign in

Explore content categories