Discussion :: Garbage Collections - General Questions (Q.No.8)
|Seshi said: (May 14, 2011)|
|We can also destroy the objects by calling the finalize method.|
|Manish said: (Mar 2, 2015)|
|Option B is correct as per the question, it is written that "programmer to destroy an object x". It is not stated that whether the object is created by new keyword or without new keyword.
If the objects are created without new keyword then garbage collector will not collect that object. In order to remove that object from memory the programmer have to invoke finalize() method.
|Charudatta said: (Aug 25, 2015)|
|Option B is not correct, because finalize() is only called just prior to garbage collection. It used to releasing system resources before the object destroy. finalize() is not use to destroy the specified object.|
|Debdeep said: (Feb 8, 2018)|
Refer this example.
public void finalize() throws Throwable
public class ProgramQ
public static void main(final String args) throws Throwable
MyObject my = new MyObject();
my = null;
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.