Destructors in Java Assignment Help

Don’t we have Destructors in Java

Java using the feature which is called garbage collector. It has its own memory management. In C# and Java both languages have the features of garbage collector and they don’t need to worry about the destructors.

Whereas java is a byte code language and have strong or huge garbage detection. We don’t need to use destructors like C++. The new operator in java done the same process of allocating memory.

Java does not support destructor in the way that C++ provides. C++ has direct destructors that we can write in our code and it will clear object once object goes out of scope.

But that is not case in Java, you can’t simply predict when object is going out of scope and when to destroy object, to do this java has concept called Garbage Collection.

Garbage Collector takes care of clearing up memory allocated to object. It has finalize method which is entirely discretion of Garbage Collector. So as in C++ ‘delete’ or ‘free()’ is used to release allocated memory in java that work is done by finalize and Garbage Collector.

Destructor in java the (garbage collection) are very important things to get clear in any programming language as this is the start where you can actually get how things are done at the background to manage memory space. So since Java is Garbage Collector language it does not have destructor.

[vfb id=1]

Share This