Re: patch: add a finalizer to AbstractJdbc1Statement - Mailing list pgsql-jdbc

From Barry Lind
Subject Re: patch: add a finalizer to AbstractJdbc1Statement
Date
Msg-id 3F4937C9.1040803@xythos.com
Whole thread Raw
In response to patch: add a finalizer to AbstractJdbc1Statement  (Oliver Jowett <oliver@opencloud.com>)
List 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@postgresql.org



pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: SetMaxFieldSize
Next
From: Paul Thomas
Date:
Subject: Re: resultset.first() untrappable error