Re: Long running open connections badly leak memory

From: Alin Sinpalean (alin_at_earthling.net)
Date: 02/19/05


Date: 19 Feb 2005 10:39:04 -0800

Joerg von Frantzius wrote:
> Hi,
>
> I wrote a batch import process that uses connection pooling, i.e. the

> connections are never closed until the process is finished. I am
writing
> large chunks of data (byte[]) into the database, and I made
absolutely
> sure that my application does not hold any references to the byte[]
> objects. However, the process increasingly consumes memory until an
> OutOfMemoryError, and I tracked it down to the Microsoft JDBC driver
> still holding references to the byte[] objects. The workaround is to
> clear the pool "from time to time", closing its connections. When I
do
> that, the memory is properly reclaimed by the GC.
>
> This "from time to time" involves some unsatisfying heuristics,
though
> (apart from the inconvenience of having to find the pool and access
it).
>
> If the driver is doing any caching on purpose, it should be
documented
> somewhere, and it should be configurable. My guess is that it's not
on
> purpose, though. I can't see much sense in holding on to written data

> after a transaction is finished.
>
> In case any driver developer should be interested, using a profiling
> tool I found references from the following driver classes to a byte[]

> object that should normally be reclaimed by the GC:
> com.microsoft.jdbc.sqlserver.SQLServerPacketizingDataConsumer and
> com.microsoft.jdbc.sqlserver.tds.TDSConnection

The MS driver does indeed do a lot of unnecessary caching (such as
caching the whole ResultSet in direct mode), but I don't think this is
your problem here.

You are closing all JDBC resources (i.e. connections, statements and
result sets), aren't you? Even if SQLExceptions are thrown...

Alin,
The jTDS Project.



Relevant Pages

  • Re: SQL CallableStatement execute and close
    ... > your performance (again ignoring caching). ... > compilation costs again. ... > have a cache for each connection. ... I wrote a Driver and Connection ...
    (comp.lang.java.databases)
  • Re: 300GB drive NTFS cluster size?
    ... Make sure that you are using the driver provided by the manufacturer ... You may also want to disable write caching for ... Disk management ...
    (microsoft.public.win2000.file_system)
  • Re: SQL CallableStatement execute and close
    ... your performance (again ignoring caching). ... compilation costs again. ... have a cache for each connection. ... I wrote a Driver and Connection ...
    (comp.lang.java.databases)
  • Re: EJBs & CMP with real database users
    ... I am afraid that J2EE will not help you very much here. ... The datasources are defined ... (url, driver, user, password, etc) ... I think that you can't use connection pooling at all. ...
    (comp.lang.java.databases)
  • Re: Disable write caching?
    ... How do you disable write caching if the option is grayed ... >Curiosity, why turn it off? ... All the computers that I have access to, ... it's an option thru the driver. ...
    (microsoft.public.windowsxp.general)