Rev 37702 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{reg.finalizer}\alias{reg.finalizer}\title{Finalization of Objects}\description{Registers an \R function to be called upon garbage collection ofobject or (optionally) at the end of an \R session.}\usage{reg.finalizer(e, f, onexit = FALSE)}\arguments{\item{e}{Object to finalize. Must be environment or external pointer.}\item{f}{Function to call on finalization. Must accept a single argument,which will be the object to finalize.}\item{onexit}{logical: should the finalizer be run if the object isstill uncollected at the end of the \R session?}}\value{\code{NULL}.}\note{The purpose of this function is mainly to allow objects that refer toexternal items (a temporary file, say) to perform cleanup actions whenthey are no longer referenced from within \R. This only makes sensefor objects that are never copied on assignment, hence the restrictionto environments and external pointers.}\seealso{\code{\link{gc}} and \code{\link{Memory}} for garbage collection andmemory management.}\examples{f <- function(e) print("cleaning....")g <- function(x){ e <- environment(); reg.finalizer(e,f) }g()invisible(gc()) # trigger cleanup}\keyword{programming}\keyword{environment}