reg.finalizer
Finalization of Objects

Description

Registers a function to be called on object finalization.

Usage

reg.finalizer(e, f, onexit = FALSE)

Arguments

e an environment or an external pointer.
f a single-argument finalization function. The object e will be passed to the function when the object e is no longer in use and has been garbage collected.
onexit a logical value. If TRUE, the finalizer is called at the end of a session if the object is still alive. If FALSE (the default), it clears the finalizer on exit.

Details

reg.finalizer registers a single-argument function that is called when the object e is no longer in use and has been garbage collected. Or, if onexit=TRUE, at the end of the session if the object is still alive.
The finalizer function is evaluated with user interrupts suspended (see suspendInterrupts).
Value
returns NULL.
Differences between Spotfire Enterprise Runtime for R and Open-source R
The argument e can be any type of object in Spotfire Enterprise Runtime for R.
See Also
gc
Examples
e <- new.env()
reg.finalizer(e, function(x) print("collection is invoked..."))
invisible(gc()) # The environment in e is still alive
e <- NULL       # Now the environment is dead
invisible(gc()) # ...and gets collected
# [1] "collection is invoked..."

e <- new.env() reg.finalizer(e, function(x) print("collection is invoked..."), onexit = TRUE) invisible(gc()) # The environment in e is still alive # q() # When the session ends, the function will run...

Package base version 6.1.4-13
Package Index