title: Replacing finalize() in Java
body: <p><code>Object.finalize()</code> is deprecated in Java 9, and I think I understand the reasons why, but I'm having trouble seeing how to replace it.</p>
  
  <p>I have a utility class called Configuration which essentially has a single instance that owns everything in the application and lasts for the duration of the application. One of the services it provides is logging: on first request to log a message, a logger is created (for various legacy reasons it's my own Logger rather than a standard one), with a reference held in a field of the Configuration object, and on application termination, whether normal or abnormal, I want to release any resources held by the logger (which is a black box since users of my library can supply their own implementation). </p>
  
  <p>Currently this is achieved with a <code>Configuration.finalize()</code> method that calls <code>logger.close()</code>.</p>
  
  <p>What should I be doing instead?</p>