Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 72E981337A5D for ; Wed, 6 Apr 2011 19:53:27 -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 14918-08 for ; Wed, 6 Apr 2011 22:53:17 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id E9B7C1337B47 for ; Wed, 6 Apr 2011 19:53:15 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id p36MrFGN006973 for ; Wed, 6 Apr 2011 19:53:15 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id p36MeY9S086694 for pgsql-jdbc@postgresql.org; Wed, 6 Apr 2011 19:40:34 -0300 (ADT) (envelope-from news) From: Lew X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: Memory leak ? Date: Wed, 06 Apr 2011 18:40:36 -0400 Organization: albasani.net Lines: 77 Message-ID: References: <4D9C3E01.9030403@xgs-france.com> <87hbab6492.fsf@mnc.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: news.albasani.net; logging-data="DZA9FgxwJ8ddKdSjXsx9wpTnFqp+23fgVRHOFwhabFeV0eDv6JJimNzdggbgHZZA8D1LM44w8Dvy52eGyxyLkRmrZ00rNs1Ub9y7VvwHQFVWhml7YelPx81+GmSZ1IfK"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 In-Reply-To: <87hbab6492.fsf@mnc.ch> Cancel-Lock: sha1:mqoKLyWnqZlsiav971w39b9XRbI= To: pgsql-jdbc@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/42 X-Sequence-Number: 21768 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? "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." >> 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'. In the OP's case he did the right thing by closing just the last 'ResultSet', since he wanted his 'Statement' to stay alive. > > 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. I tend not to conflate the issues of memory resources and external resources like database connections. > 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? One should never have depended exclusively on the GC to close resources in any event. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg