Calling getMetaData() without closing the connection lead to a memory leak
--------------------------------------------------------------------------

                 Key: DBCP-330
                 URL: https://issues.apache.org/jira/browse/DBCP-330
             Project: Commons Dbcp
          Issue Type: Bug
    Affects Versions: 1.4
         Environment: Linux Mint 8 Helena - Universal Edition

Linux version 2.6.31-14-generic (bui...@rothera) (gcc version 4.4.1 (Ubuntu 
4.4.1-4ubuntu8) ) #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009

java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)
            Reporter: Tim
            Priority: Minor


In my program, I am using a BasicDataSource to get my database connections. I 
have to keep one of the connection alive and thus never close it. On this 
connection, I have to periodically get the metadata (call the getMetaData() 
method) for my processing.
However, I have noticed that each call to this method create a new 
DelegatingDatabaseMetaData instance which can't be garbage collected until the 
connection is closed. This creation of DelegatingDatabaseMetaData will finally 
consume all the memory and generate a OutOfMemory error.

Actually, in it's constructor, the DelegatingDatabaseMetaData class calls its 
super constructor (from the AbandonedTrace class) which creates a reference 
(parent.addTrace(this);) from the connection to the DelegatingDatabaseMetaData. 
This reference prevent the DelegatingDatabaseMetaData to be collected until the 
Connection is closed.



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to