I have strange situation. When executing this code, NetBeansIDE profiler shows memory leak (and after some time elapses, application quit because of insufficient memory):
public class SomeClass extends TimerTask {
private static final Timer timer = new Timer();
public SomeClass() {
//Delay 0, repeat every 20ms
timer.scheduleAtFixedRate(SomeClass.this, 0, 20);
}
@Override
public void run() {
try (Connection connDB =
DriverManager.getConnection(
"jdbc:derby:someDataBase;create=true");
Statement st = connDB.createStatement()) {
//Some code in normal situation. But the problem
//exists even without additional code..
} catch (SQLException ex) {
Logger.getLogger(SomeClass.class.getName()).log(
Level.SEVERE, null, ex);
}
}
}
Here are the snapshots:
Memory (Heap)
Memory (GC) - Surviving generations
Is this some Derby database bug?
Running on JDK8_u31, Derby version/package: db-derby-10.11.1.1-lib.
EDIT 1:
When switched to HSQLDB database - no more memory leaks occurred while thousands of connections were opened and closed:
Wow! :)

I thought that this might be due to Statement and/or Connection not implementing AutoCloseable. However, according to the JLS, that would be a compilation error ... and the javadocs say that those interfaces do implement it.
It looks like it is a Derby bug, and it might be related to this one:
Use the memory profiler to try to see what classes of object are leaking. That should give you some more clues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With