Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 5E3851337BBB for ; Wed, 6 Apr 2011 19:53:34 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 39326-08 for ; Wed, 6 Apr 2011 22:53:16 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id A3E431337B2F 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 p36MrFGL006973 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 p36MYmIi077424 for pgsql-jdbc@postgresql.org; Wed, 6 Apr 2011 19:34:48 -0300 (ADT) (envelope-from news) From: Lew X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: Memory leak ? Date: Wed, 06 Apr 2011 18:34:50 -0400 Organization: albasani.net Lines: 75 Message-ID: References: <4D9C3C6E.8030502@xgs-france.com> <4D9C40BA.3080606@nitorcreations.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: news.albasani.net; logging-data="AhIHZbK2CDMmVKGSJcXnELJvj/JW81iyYl89H4NWs47SK91ty+GxZiBkP3rFIY5r4xH1NQo1yQYbczZ/mLIbD1pZ4vl5jLSKUb0Q4PfhI/RicpvSHXGKONy2mjQoHgJy"; 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: <4D9C40BA.3080606@nitorcreations.com> Cancel-Lock: sha1:P8FuGpz96LyhEvowJhQYQGilHjQ= 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/43 X-Sequence-Number: 21769 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 : "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