• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

com.mysql.jdbc.Connection openConnections memory leak

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am working on a system that pools JDBC MySQL connections.

It fell over the other day with an out of memory error.

Looking at the .hprof, it says that one MySQL JDBC connection has a retained size of 27Mb. According to the hprof that was all in the com.mysql.jdbc.Connection.openConnections field.
Why would this field be accumulating values, and is there any way to clear it?

John
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you closing your connections when done?
 
John Farrel
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Are you closing your connections when done?



The pool is keeping connections alive for re-use as it should.

I've found the issue... the ResultSest and Statements using the connection aren't being closed, and a MySQL JDBC Connection keeps some sort of log of the those until the connection itself is closed.

However, it's possible to turn this functionality off by adding dontTrackOpenResources=true to the MySQL JDBC URL.

 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Farrel wrote:However, it's possible to turn this functionality off by adding dontTrackOpenResources=true to the MySQL JDBC URL.


Instead of such hacks, I'd suggest to stick to best practices and explicitly close the Statements and ResultSets after use. Every (reasonable) JDBC tutorial says so.

You should call close() on connections obtained from connection pool too, of course. This is the correct way to return the connection to the pool (mentioning it because it isn't entirely clear from your post whether you're doing so). Some connection pools might ensure that resources created on that connection which weren't properly closed are freed, but this depends on the particular connection pool you're using.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic