Uploaded image for project: 'Commons DBCP'
  1. Commons DBCP
  2. DBCP-332

Closing BasicDataSource doesn't deregister JDBC driver, causing memory leak

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.3, 1.4
    • None
    • None

    Description

      BasicDataSource's method close() doesn't deregister JDBC driver. This causes permgen memory leaks in web server environments, during context reloads. For example, using Tomcat 6.0.26 with Spring, and BasicDataSource declared in Spring context, there is a message printed at web application reload:

      SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

      I was able to fix it by overriding close method this way:

      public class XBasicDataSource extends BasicDataSource {
          @Override
          public synchronized void close() throws SQLException {
              DriverManager.deregisterDriver(DriverManager.getDriver(url));
              super.close();
          }
      }
      

      but I think it should be probably the default behavior of BasicDataSource. Or perhaps there should be some flag/setting on BasicDataSource, named "deregisterDriverAtClose" or so.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            grzegorzborkowski Grzegorz Borkowski
            Votes:
            20 Vote for this issue
            Watchers:
            13 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment