c3p0 leaks memory when mysql global variable wait_timeout is set to a low value.
In this case, mysql server closes idle connections at its own end when wait_timeout expires. C3p0 detects an invalid connection but does not clean it up properly. The JDBC4Connection and its Properties stay resident in memory and are never Garbage Collected.
In order to reproduce the bug, I am attaching a very simple test case file.
Please use a mysql server where wait_timeout is set to 3 (seconds).
With JVM variables -Xmx16m and -Xms16m, the applications gets an OutOfMemory on my system within a couple of minutes, with c3p0 pooling.
With direct JDBC via Mysql Driver, it stays stable.
Version I used :
c3p0 - 0.9.1.2
Mysql connector/J - 5.1.15
JDK - 1.6 u 21