From Waclaw.Marcin.Kusnierczyk at idi.ntnu.no  Tue Jun 30 11:11:25 2009
From: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no (Wacek Kusnierczyk)
Date: Tue, 30 Jun 2009 11:11:25 +0200
Subject: [Rd] S4 and connection slot [Sec=Unclassified]
In-Reply-To: <4A49120D.7040605@fhcrc.org>
References: <42C7503E0B99F248B06BC65E7D2B4E020122C50FB2AB@EX2K7-CCR.AAD.GOV.AU>		<4A48BF64.7070004@fhcrc.org>	<8b356f880906290941v5f51c4c4pb12d40f510f56bc8@mail.gmail.com>
	<4A49120D.7040605@fhcrc.org>
Message-ID: <4A49D6BD.6080506@idi.ntnu.no>

Martin Morgan wrote:

[...]


>
> ## Attempt two -- initialize
> setClass("Element",
>          representation=representation(conn="file"))
>
> setMethod(initialize, "Element", function(.Object, ..., conn=file()) {
>     callNextMethod(.Object, ..., conn=conn)
> })
>
> new("Element")
> ## oops, connection created but not closed; gc() closes (eventually)
> ## but with an ugly warning
> ## > gc()
> ##            used  (Mb) gc trigger  (Mb) max used  (Mb)
> ## Ncells   717240  38.4    1166886  62.4  1073225  57.4
> ## Vcells 37333395 284.9   63274729 482.8 60051033 458.2
> ## > gc()
> ##            used  (Mb) gc trigger  (Mb) max used  (Mb)
> ## Ncells   715906  38.3    1166886  62.4  1073225  57.4
> ## Vcells 37335626 284.9   63274729 482.8 60051033 458.2
> ## Warning messages:
> ## 1: closing unused connection 3 ()
>
> setClass("ElementX", contains="Element")
> ## oops, two connections opened (!)

yes, that's because of the nonsense double call to the initializer while 
creating a subclass.  the conceptual bug in the s4 system leads to this 
ridiculous behaviour in your essentially correct and useful pattern.

vQ



[Rd] S4 and connection slot [Sec=Unclassified]
Wacek Kusnierczyk