Skip to main content

Posts

Showing posts from December, 2017

Why there is no 'Destructor' method in java ?

down vote accepted Because Java is a garbage collected language you cannot predict when (or even if) an object will be destroyed. Hence there is no direct equivalent of a destructor. There is an inherited method called   finalize , but this is called entirely at the discretion of the garbage collector. So for classes that need to explicitly tidy up, the convention is to define a   close method and use finalize only for sanity checking (i.e. if   close   has not been called do it now and log an error). Credit: https://stackoverflow.com/questions/171952/is-there-a-destructor-for-java