From murdoch at stats.uwo.ca  Wed Jul  8 03:20:11 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue, 07 Jul 2009 21:20:11 -0400
Subject: [Rd] reg.finalizer(..., add=FALSE)?
In-Reply-To: <59d7961d0907071736j73f22031y291662df97968293@mail.gmail.com>
References: <59d7961d0907071736j73f22031y291662df97968293@mail.gmail.com>
Message-ID: <4A53F44B.3090707@stats.uwo.ca>

On 07/07/2009 8:36 PM, Henrik Bengtsson wrote:
> Is it possible to (i) clear or (ii) override already registered
> finalizer functions, e.g. reg.finalizer(e, f, add=FALSE) cf.
> on.exit(..., add=FALSE)?

No, but you can have the finalizer function call something else, and 
change the thing it calls.  E.g.

reg.finalizer(env, function (...) CleanUp(...))

will call CleanUp in the global environment (the environment of the 
anonymous finalizer); change that function and the cleanup behaviour 
will change.

Duncan Murdoch

> 
> Currently:
> 
>> env <- new.env()
>> reg.finalizer(env, function(...) cat("Finalizer A!\n"))
> NULL
>> reg.finalizer(env, function(...) cat("Finalizer B!\n"))
> NULL
>> reg.finalizer(env, function(...) cat("Finalizer C!\n"))
> NULL
>> gc()
>          used (Mb) gc trigger (Mb) max used (Mb)
> Ncells 115827  3.1     350000  9.4   350000  9.4
> Vcells  77109  0.6     786432  6.0   370917  2.9
>> rm(env)
>> gc()
> Finalizer C!
> Finalizer B!
> Finalizer A!
>          used (Mb) gc trigger (Mb) max used (Mb)
> Ncells 115932  3.1     350000  9.4   350000  9.4
> Vcells  77648  0.6     786432  6.0   370917  2.9
> 
> I wish to have only finalizer "C" to run.
> 
> /Henrik
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] reg.finalizer(..., add=FALSE)?
Duncan Murdoch