pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guillaume Cottenceau <gc@mnc.ch>
To: Lew <noone@lewscanon.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Memory leak ?
Date: Thu, 07 Apr 2011 09:05:19 +0200
Message-ID: <8739luy21c.fsf@mnc.ch> (raw)
In-Reply-To: <iniq52$ovi$1@news.albasani.net>
References: <4D9C3E01.9030403@xgs-france.com>
	<87hbab6492.fsf@mnc.ch>
	<iniq52$ovi$1@news.albasani.net>

Lew <noone 'at' lewscanon.com> writes:

> Guillaume Cottenceau wrote:
>> Pierre Le Mouëllic 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)
>
> So?  Why is that an issue?

Did I say it is an issue?

> <http://download.oracle.com/javase/6/docs/api/java/sql/ResultSet.html;
>
> "A ResultSet object is automatically closed when the Statement object
> that generated it is closed, re-executed, or used to retrieve the next
> result from a sequence of multiple results."

Yes, it is not an issue.

>>> In eclipse Helios profiler, Jdbc3ResultSet live instances increase (and never
>>> decrease). Same thing with
>>
>> Garbage collection is not predictable, closing resultsets [sic] (and
>> statements) is strongly adviced if you want to release JDBC
>> resources in a timely manner.
>
> No.
>
> Closing a 'ResultSet' is actually not advised.  Well, sometimes, but
> generally you should close its 'Statement'.  

I'm no expert on that, so it's one more reason why I'm not going
to lose too much time on that by answering once to illustrate my
claims, and then let it go if that creates more fuss. I hope I
can learn from this actually so that's not a call from you to not
answer that message if you see wrong claims.

I'm stating closing (of resultsets and statements) is adviced
from memories of messages on this list and other lists, and this
seems to be supported by the documentation over there:

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

In particular:

"Releases this ResultSet object's database and JDBC resources
immediately instead of waiting for this to happen when it is
automatically closed."

I don't see why it would be "actually not adviced" as you say. So
there is an API, whose name is "close" which is similar to other
names used in java API to immediately release external resources
instead of waiting for the GC to do so, and whose documentation
says the same thing, but it would be adviced to not use it? Seems
odd.

> In the OP's case he did the right thing by closing just the
> last 'ResultSet', since he wanted his 'Statement' to stay
> alive.

Closing the two first resultsets would not allow this statement
to stay alive? That doesn't seem supported by the documentation
of the close method.

-- 
Guillaume Cottenceau



view thread (10+ messages)

Message-ID: <8739luy21c.fsf@mnc.ch>
Permalink:  ../8739luy21c.fsf@mnc.ch/
Also on:    postgresql.org/message-id/8739luy21c.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, noone@lewscanon.com
  Subject: Re: Memory leak ?
  In-Reply-To: <8739luy21c.fsf@mnc.ch>
  References: <4D9C3E01.9030403@xgs-france.com> <87hbab6492.fsf@mnc.ch> <iniq52$ovi$1@news.albasani.net> <8739luy21c.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