title: Spring Boot - Memory Leak - H2 Database - Does not unregister driver
body: <p>Completely reworked due to new information:</p>
  <ul>
  <li><p>Initial problem: JBoss killed itself with &quot;OutOfMemoryError: Metaspace&quot;, when redeploying a simple Spring Boot app (2.2.6) multiple times</p>
  </li>
  <li><p>Using a heap dump I found that the H2 driver (1.4.200) kept a reference and leading to a problem <a href="https://i.stack.imgur.com/rbJvl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rbJvl.png" alt="enter image description here" /></a></p>
  </li>
  <li><p>Afterwards I checked why tomcat does not behave like this, finding</p>
  <p><code>The web application [killerApp] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.</code></p>
  </li>
  </ul>
  <p>So it just works in a tomcat, because it is smart enough to notice the memory leak and preventing it. The JBoss does not do it and runs into trouble...</p>
  <p>It looks like a standard spring boot app with H2 is misbehaving regarding the handling of unregistering the H2 driver...at least this is my take away.</p>
  <p>I additionally found this one: <a href="https://github.com/spring-projects/spring-boot/issues/2612" rel="nofollow noreferrer">GitHub - Spring Boot - Discussion about unregister managed JDBC drivers</a></p>
  <p>Now I am unsure, who is at &quot;fault&quot;?</p>
  <ol>
  <li>Me because I would need to take care of unregistering the H2 driver properly</li>
  <li>Me because I misconfigured the Spring Boot App</li>
  <li>The H2 driver for holding an internal state?</li>
  <li>Spring boot for relaying on Tomcat to tidy up</li>
  </ol>
  <p>Best and many thanks</p>