Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2C83E1337B47 for ; Thu, 7 Apr 2011 04:05:33 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 42691-08 for ; Thu, 7 Apr 2011 07:05:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.mnc.ch (62-2-77-205.static.cablecom.ch [62.2.77.205]) by mail.postgresql.org (Postfix) with ESMTP id 94937133655C for ; Thu, 7 Apr 2011 04:05:21 -0300 (ADT) Received: from localhost (mail2.mnc.ch [127.0.0.1]) by mail.mnc.ch (Postfix) with ESMTP id BC46C23051; Thu, 7 Apr 2011 07:05:20 +0000 (GMT) X-Virus-Scanned: amavisd-new at mnc.ch Received: from mail.mnc.ch ([127.0.0.1]) by localhost (mail2.mnc.ch [127.0.0.1]) (amavisd-new, port 10025) with LMTP id Zr01gfxt1OS3; Thu, 7 Apr 2011 07:05:19 +0000 (GMT) Received: from meuh.localdomain (62-2-77-204.static.cablecom.ch [62.2.77.204]) by mail.mnc.ch (Postfix) with ESMTP id E5FCB23050; Thu, 7 Apr 2011 07:05:19 +0000 (GMT) Received: by meuh.localdomain (Postfix, from userid 1000) id D6066110279; Thu, 7 Apr 2011 09:05:19 +0200 (CEST) To: Lew Cc: pgsql-jdbc@postgresql.org Subject: Re: Memory leak ? References: <4D9C3E01.9030403@xgs-france.com> <87hbab6492.fsf@mnc.ch> From: Guillaume Cottenceau X-Hashcash: 1:21:110407:noone@lewscanon.com::5j3VEYcFmw+D0S0A:00000000000000000000000000000000000000000014/5 X-Hashcash: 1:21:110407:pgsql-jdbc@postgresql.org::I+yQmvuppiqhq3hn:0000000000000000000000000000000000000BbC Date: Thu, 07 Apr 2011 09:05:19 +0200 In-Reply-To: (Lew's message of "Wed\, 06 Apr 2011 18\:40\:36 -0400") Message-ID: <8739luy21c.fsf@mnc.ch> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201104/45 X-Sequence-Number: 21771 Lew 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? > > > "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