pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guillaume Cottenceau <gc@mnc.ch>
To: Pierre Le Mouëllic <pierre.lemouellic@xgs-france.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Memory leak ?
Date: Wed, 06 Apr 2011 12:52:41 +0200
Message-ID: <87hbab6492.fsf@mnc.ch> (raw)
In-Reply-To: <4D9C3E01.9030403@xgs-france.com>
References: <4D9C3E01.9030403@xgs-france.com>

Pierre Le Mouëllic <pierre.lemouellic 'at' xgs-france.com> writes:

> With this code :
>
> public class TestJDBC {

[...]

>             try {
>                 sQLStatement.setInt(1, 2602);
>                 rs = sQLStatement.executeQuery();
>                 sQLStatement.setInt(1, 2604);
>                 rs = sQLStatement.executeQuery();
>                 sQLStatement.setInt(1, 2605);
>                 rs = sQLStatement.executeQuery();
>             } catch (SQLException e) {
>             }
>             finally{
>
>                 try {
>                     if(rs!=null)
>                         rs.close();

e.g. you explicitely close only the last resultset of the three
you produced (assuming no exception)

> In eclipse Helios profiler, Jdbc3ResultSet live instances increase (and never
> decrease). Same thing with

Garbage collection is not predictable, closing resultsets (and
statements) is strongly adviced if you want to release JDBC
resources in a timely manner.

I have never used this profiler but it would be interesting to
know if any references are keeping these objects alive (then we
could begin thinking of a leak), or if they are only not yet
collected by the GC because it decided not to do it yet for any
reason.

Interestingly, the diff between:

http://download.oracle.com/javase/1.4.2/docs/api/java/sql/Statement.html#close()

and:

http://download.oracle.com/javase/6/docs/api/java/sql/Statement.html#close()

shows they've removed "Statement object is automatically closed
when it is garbage collected." no idea why though. probably a
more seasoned PG-JDBC dev/user would have?

-- 
Guillaume Cottenceau



view thread (10+ messages)  latest in thread

Message-ID: <87hbab6492.fsf@mnc.ch>
Permalink:  ../87hbab6492.fsf@mnc.ch/
Also on:    postgresql.org/message-id/87hbab6492.fsf@mnc.ch

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: gc@mnc.ch, pierre.lemouellic@xgs-france.com
  Subject: Re: Memory leak ?
  In-Reply-To: <87hbab6492.fsf@mnc.ch>
  References: <4D9C3E01.9030403@xgs-france.com> <87hbab6492.fsf@mnc.ch>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox