Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Garbage collection in Java is the automatic process for memory management.It is the way to remove/destroy unused objects.
In C language allocation and deallocation of memory is the manual process. But in java, deallocating memory process is handled automatically by the garbage collector.
Basically, Automatic garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects.
To determine which objects are no longer in use, the JVM intermittently use Mark and Sweep algorithm.
Basically, it consists of two steps.
In this step, the Garbage collector identifies the used and unused objects and mark the used object.
Step 1: SweepIn this step, all unused objects will be deleted. All of the heap memory which was used by unused objects is free now and available for further use.
Automatic deallocation makes java memory efficient.Programmers don’t have to worry about memory as It is automatically done by the garbage collector.
There are several ways to make an object eligible for garbage collection.
2. Assigning a reference to another:
For example :
3. Anonymous object:
Example:
Before destroying an object, Garbage Collector calls finalize() method on the object to perform cleanup activities. Once finalize() method completes, Garbage Collector destroys that object.
This method is present in the Object class.
Once an object is eligible for garbage collection, it may not destroy immediately by GC.It will be garbage collected once GC will be run and we can’t predict when GC will be run.Although we don’t know when will GC run, we can request JVM to run GC by using System.gc() method.
Hope this post will give an idea about Garbage Collection in java
Thank you !!
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.
Osama
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.