Re: patch: add a finalizer to AbstractJdbc1Statement

From: Barry Lind <blind(at)xythos(dot)com>
To: Oliver Jowett <oliver(at)opencloud(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: patch: add a finalizer to AbstractJdbc1Statement
Date: 2003-08-24 22:10:17
Message-ID: 3F4937C9.1040803@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Patch applied.

thanks,
--Barry

Oliver Jowett wrote:
> This patch adds a finalizer to AbstractJdbc1Statement that closes the
> statement. Without this, when server-side preparation is in use statements
> that are executed then discarded without an explicit close() will leak
> resources on the backend while that connection remains open, as a DEALLOCATE
> never gets executed.
>
> Objects with a finalizer are more expensive to create (depending on the VM).
> If it's too much of a price to pay in the general case, there's another
> approach that uses phantom references and only pays the cost when backend
> resources are actually allocated, but the code becomes much more complex.
>
> -O
>
>
> ------------------------------------------------------------------------
>
> Index: src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v
> retrieving revision 1.31
> diff -u -c -r1.31 AbstractJdbc1Statement.java
> *** src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java 11 Aug 2003 21:12:00 -0000 1.31
> --- src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java 17 Aug 2003 13:15:49 -0000
> ***************
> *** 721,726 ****
> --- 721,735 ----
> result = null;
> }
>
> + /**
> + * This finalizer ensures that statements that have allocated server-side
> + * resources free them when they become unreferenced.
> + */
> + protected void finalize() {
> + try { close(); }
> + catch (SQLException e) {}
> + }
> +
> /*
> * Filter the SQL string of Java SQL Escape clauses.
> *
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2003-08-24 22:11:06 Re: patch: fix 'compile' target to do correct dependency checking
Previous Message Dave Tenny 2003-08-23 15:29:55 Re: connection/statement becomes unstable following SQLException