Problem Statement
How are object cleanup tasks handled in Java and what are the limitations of finalisers?
Explanation
In Java, there is no explicit destructor mechanism like in C++, but you can override `finalize()` or implement `AutoCloseable` and use try-with-resources for resource cleanup. However, `finalize()` is deprecated because its execution timing is unpredictable, it can delay resource release, and may introduce performance overhead. Therefore good design uses explicit close methods and avoids relying on GC for critical resource cleanup.
Practice Sets
This question appears in the following practice sets: