Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VYHEt-0000Xc-8Q for pgsql-jdbc@arkaria.postgresql.org; Mon, 21 Oct 2013 15:17:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VYHEs-0003Fm-41 for pgsql-jdbc@arkaria.postgresql.org; Mon, 21 Oct 2013 15:17:50 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VYHEr-0003FW-Dp for pgsql-jdbc@postgresql.org; Mon, 21 Oct 2013 15:17:49 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VYHEm-0001Iz-Qu for pgsql-jdbc@postgresql.org; Mon, 21 Oct 2013 15:17:47 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id CE98629427; Mon, 21 Oct 2013 08:17:43 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id C91DBB016E; Mon, 21 Oct 2013 08:17:43 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id ADCCE120032; Mon, 21 Oct 2013 08:24:45 -0700 (PDT) Received: from [192.168.43.149] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA; Mon, 21 Oct 2013 08:24:44 -0700 (PDT) Message-ID: <52654590.1050600@vmware.com> Date: Mon, 21 Oct 2013 18:17:36 +0300 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: "Heiko W. Rupp" CC: Vitalii Tymchyshyn , PG-JDBC Mailing List Subject: Re: Remove usage of finalizers ? References: <9E5438C0-0A2E-4543-BE06-1E7A6D0E3B83@pilhuhn.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -7.3 (-------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org On 21.10.2013 13:09, Heiko W. Rupp wrote: > Am 21.10.2013 um 11:34 schrieb Vitalii Tymchyshyn: >> Note that removing finalizers without introducing some other mechanism, like reference queues, would introduce server side leaks on poorly written yet correct applications! > > Server side leaks are introduced the moment that you rely on a finalizer being called (close to the time the object is no longer needed). > Per JLS, the finalizers are a) not guaranteed to ever run, b) run in any specific order c) at any given time. > > And the other mechanisms exist -- close() calls. Software that relies on the finalizer for this cleanup may show unpredictable > behavior. If we can't get rid of the finalizer completely, I wonder if we could arrange things so that we could avoid the finalizer overhead when there are server-side resources associated with the statement. I would guess that in most cases that you don't close a Statement properly, it's a very short-lived Statement used to run a single query. Such a statement will typically not have any server-side resources associated with it. Actually, we already seem to use PhantomReferences to clean up orphaned SimpleQuery and Portal objects. AFAICS those are the things that actually represent server-side resources. Why do we even have a finalizer in AbstractJdbc2Statement? Perhaps we used to rely on the finalizer to clean up things, but later added the more fine-grained PhantomReferences to the underlying objects, making the finalizer redundant? > Another reason to get rid of finalize() methods is that Object creation is several hundred times slower with the finalize() > methods present, as not only the Statement etc. is created, but also the Finalizer and the later needs to be put on the finalizer > queue. Josh Bloch talks about 5.6ns vs 2400ns for a simple object in "Effective Java, 2nd edition". > That is a penalty everyone has to pay - even if they close Statements etc correctly. That's still negligible compared to sending a statement to the remote host and getting the result back, though. - Heikki -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc