Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I recently noticed (via jmap+jhat) that my App was leaking storing many instances com.mysql.jdbc.Field class
- I double checked my code to make sure I was closing all PreparedStatements, find a few missing but it didn't change the outcome.
- Some PreparedStatement are created and closed right away
- Several others are created at start up and reused many times
- I am using org.apache.tomcat.jdbc.pool.DataSource as connection pool

What can cause this type of behavior?

share|improve this question

1 Answer

Are you closing all of your preparedstatements / result sets using:

PreparedStatement stmt (possible assignment here);
try
{
 // do all work with prepared statement
 ResultSet rs;
 try
 {
   while (rs.next()) ...
   // process results
 }
 finally
 {
   rs.close();
 }
}
finally
{
  stmt.close();
}

So that you guarantee all result sets are closed when finished (regardless of exceptions) and all statements are closed (regardless of exceptions)? Obviously there are other ways to write that, but the idea is the same.

If you're doing all of that properly, then unless you have so many references that it's taking up an inordinate amount of memory, it's almost certainly OK and nothing needs to be done about it.

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.