Memory leak in JDBC4Connection

前端 未结 3 1024
花落未央
花落未央 2021-02-10 12:34

I\'m trying to catch a memory leak in one of our Java daemons, and after dumping the memory and analyzing it via Memory Analyzer Tool, noticed that most of the leak is caused by

相关标签:
3条回答
  • 2021-02-10 13:17

    I'm pretty sure that we closing all of the MySQL resources

    If not 100% sure, please show how you're closing your connections.

    Are you using a connection pool? Would it happen to have a pool size of 10?

    0 讨论(0)
  • 2021-02-10 13:27

    Sounds like you have a connection pool with 10 connections, and the pool has statement caching enabled, without having the cache size limited to a healthy amount.

    0 讨论(0)
  • 2021-02-10 13:32

    Duffymo is almost certainly right. In the past when we've had memory leaks, it's practically ALWAYS the MySQL JDBC driver. Just forgetting to close one little ResultSet or Connection or Statement somewhere. I ended up auditing the entire codebase for every time we used those to find the problem and ensure they get closed.

    As for the HashMap, I've seen that too. I haven't looked at the source but my impression was that the MySQL driver stored the rows (at least row values) in HashMaps internally.

    Leaking ResultSets is sadly easy. The idea of those closeable resources that take care of this themselves coming in JDK 7 or 8 really appeals to me for this reason.

    You could insert a shim class somewhere (say for Connection) to log each opened/closed resource to see if you can catch where the leak is without directly reading all your source.

    0 讨论(0)
提交回复
热议问题