Spread the love

Old Fashioned Coding Style May Help Garbage Collector to Reclaim Memory Quickly

Spread the love

Old Fashioned Coding Style May Help Garbage Collector to Reclaim Memory Quickly

In my last post about Garbage Collector I have explained how Garbage Collector works.In this post, my objective is to code in such an old fashioned manner that will help Garbage collector to reclaim its memory.

Yes!! this post is based on C++ like memory de- allocation technique.

In C++ , a new operator will allocate memory space and delete operator will delete or free up the memory space.In Java,JVM runs a low priority thread called Garbage Collector to reclaim memory while new operator remain same for allocating memory.

As Garbage Collector is a low priority thread,Lets help GC to work better



yes!! setting an object to null will ease the memory reclaim even if the program is running.
Lets create a class called pen:

public class Pen {
int countofpen=0;
public Pen() {

Now create another class called penApp:

public class penApp {
public static void main(String[] args) {
//some code
Pen pen = new Pen();
//Some code

In this old fashioned manner we can help GC to collect memory while the code is running.

Spread the love
READ  Class ByteArrayOutputStream in Java
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles



Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...


Spread the love