Overriding the finalize method is often done if you need to manually free resources (especially those that use large amounts of memory or cause locks if they were not released). For example, if you have an object that has a lock in a file or database table, you can override your finalize method to free those objects that will be used when your object is garbage collected.
As to whether redefinition of finalization is required, this is absolutely not the case. You can call System.gc () without overriding the finalize method. One word of caution, though - calling System.gc () doesn't quite dictate that the garbage collector does anything. Consider this more as a “recommendation” for the JVM to start garbage collection rather than a “credential”.
source share