title: Memory leak in c3p0 - java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool
body: <p>Environment:
  Server : Jboss 4.2.3.GA</p>
  
  <p>We are using c3p0 0.9.1.2 for connection pooling.</p>
  
  <p>Whenever we <strong>hot-deploy</strong> war files in Jboss AS are encountering the memory leak from c3p0.
  It eventually leads to <strong>“java.lang.OutOfMemoryError: PermGen space”</strong> error, we are forced to restart the our Application server.</p>
  
  <p>Has anyone came across this problem? Is there any workaround for this problem?</p>
  
  <p>The Stacktrace is as follows:</p>
  
  <pre><code>14:50:16,097 INFO  [WebappClassLoader] Illegal access: this web application instance has been stopped already.  Could not load com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
  java.lang.IllegalStateException
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1244)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
      at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:980)
      at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1406)
      at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1378)
      at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1462)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:32)
      at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:1937)
      at java.util.TimerThread.mainLoop(Timer.java:512)
      at java.util.TimerThread.run(Timer.java:462)
  14:50:22,328 ERROR [STDERR] Exception in thread "Timer-5" 
  14:50:22,329 ERROR [STDERR] java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$1DestroyResourceTask
  14:50:22,329 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:980)
  14:50:22,329 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1406)
  14:50:22,329 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1378)
  14:50:22,329 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1462)
  14:50:22,329 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:32)
  14:50:22,329 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:1937)
  14:50:22,329 ERROR [STDERR]     at java.util.TimerThread.mainLoop(Timer.java:512)
  14:50:22,329 ERROR [STDERR]     at java.util.TimerThread.run(Timer.java:462)
  14:50:22,329 ERROR [STDERR] Caused by: java.lang.ClassNotFoundException: com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask
  14:50:22,329 ERROR [STDERR]     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
  14:50:22,329 ERROR [STDERR]     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
  14:50:22,329 ERROR [STDERR]     ... 8 more
  14:50:23,081 ERROR [STDERR] Exception in thread "Timer-6" 
  14:50:23,082 ERROR [STDERR] java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$1DestroyResourceTask
  14:50:23,082 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:980)
  14:50:23,082 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1406)
  14:50:23,082 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1378)
  14:50:23,082 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1462)
  14:50:23,082 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:32)
  14:50:23,082 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:1937)
  14:50:23,082 ERROR [STDERR]     at java.util.TimerThread.mainLoop(Timer.java:512)
  14:50:23,083 ERROR [STDERR]     at java.util.TimerThread.run(Timer.java:462)
  14:51:59,105 INFO  [WebappClassLoader] Illegal access: this web application instance has been stopped already.  Could not load com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
  java.lang.IllegalStateException
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1244)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
      at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:980)
      at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1406)
      at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1378)
      at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1462)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:32)
      at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:1937)
      at java.util.TimerThread.mainLoop(Timer.java:512)
      at java.util.TimerThread.run(Timer.java:462)
  ^[[1;2C14:56:03,597 ERROR [STDERR] Exception in thread "Timer-11" 
  14:56:03,598 ERROR [STDERR] java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$1DestroyResourceTask
  14:56:03,598 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:980)
  14:56:03,598 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1406)
  14:56:03,598 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1378)
  14:56:03,598 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1462)
  14:56:03,598 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:32)
  14:56:03,598 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:1937)
  Listening for transport dt_socket at address: 8787
  14:56:03,598 ERROR [STDERR]     at java.util.TimerThread.mainLoop(Timer.java:512)
  14:56:03,598 ERROR [STDERR]     at java.util.TimerThread.run(Timer.java:462)
  14:56:03,598 ERROR [STDERR] Exception in thread "Timer-10" 
  14:56:03,607 ERROR [STDERR] java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$1DestroyResourceTask
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:980)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1406)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1378)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1462)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:32)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:1937)
  14:56:03,607 ERROR [STDERR]     at java.util.TimerThread.mainLoop(Timer.java:512)
  14:56:03,607 ERROR [STDERR]     at java.util.TimerThread.run(Timer.java:462)
  14:56:03,607 ERROR [STDERR] Exception in thread "Timer-9" 
  14:56:03,607 ERROR [STDERR] java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$1DestroyResourceTask
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:980)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1406)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1378)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1462)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:32)
  14:56:03,607 ERROR [STDERR]     at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:1937)
  14:56:03,607 ERROR [STDERR]     at java.util.TimerThread.mainLoop(Timer.java:512)
  14:56:03,607 ERROR [STDERR]     at java.util.TimerThread.run(Timer.java:462)
  14:56:03,607 ERROR [STDERR] Caused by: java.lang.ClassNotFoundException: com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask
  14:56:03,607 ERROR [STDERR]     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
  14:56:03,607 ERROR [STDERR]     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
  14:56:03,607 ERROR [STDERR]     ... 8 more
  </code></pre>