pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lew <noone@lewscanon.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Memory leak ?
Date: Wed, 06 Apr 2011 18:34:50 -0400
Message-ID: <inipq8$o3h$1@news.albasani.net> (raw)
In-Reply-To: <4D9C40BA.3080606@nitorcreations.com>
References: <4D9C3C6E.8030502@xgs-france.com>
	<4D9C40BA.3080606@nitorcreations.com>

Mikko Tiihonen wrote:
> Pierre Le Mouëllic wrote:
>> With this code :
>>
>> public class TestJDBC {
>>
>>      private static Timer timer;
>>
>>      private static Connection connDB;
>>      private static PreparedStatement sQLStatement;
>>
>>      public static void main(String[] args) throws SQLException, ClassNotFoundException {
>>
>>          connexion("jdbc:postgresql://praslin.qual.dc1:5432/G01DPM","postgres8","password");
>>
>>          timer = new Timer();
>>          timer.schedule(new local_task(), 1000L, 1000);
>>      }
>>
>>      static class local_task extends TimerTask {
>>
>>          public void run() {
>>              ResultSet rs=null;
>>              try {
>>                  sQLStatement.setInt(1, 2602);
>>                  rs = sQLStatement.executeQuery();

> Missing
> rs.close();

Not needed.

 From <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."


>>                  sQLStatement.setInt(1, 2604);
>>                  rs = sQLStatement.executeQuery();

> Missing
> rs.close();

Nope.

In fact, it's rather an antipattern to call 'ResultSet#close()' explicitly.

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

What's bizarre here is that we aren't closing the statement.

That's weird.

>>                  } catch (SQLException e) {
>>                  }
>>
>>                  rollBack();
>>              }
>>          }
>>      }

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg



view thread (10+ messages)  latest in thread

Message-ID: <inipq8$o3h$1@news.albasani.net>
Permalink:  ../inipq8$o3h$1@news.albasani.net/
Also on:    postgresql.org/message-id/inipq8$o3h$1@news.albasani.net

 · 

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: noone@lewscanon.com
  Subject: Re: Memory leak ?
  In-Reply-To: <inipq8$o3h$1@news.albasani.net>
  References: <4D9C3C6E.8030502@xgs-france.com> <4D9C40BA.3080606@nitorcreations.com> <inipq8$o3h$1@news.albasani.net>

* 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