finalize.Object {R.oo}R Documentation

Finalizer methods called when object is clean out

Description

The finalizer method should never be called explicitly!. Finalizer methods called just before the object is about to be deleted by the garbage collector.

Usage

## S3 method for class 'Object':
finalize(this, ...)

Arguments

... Not used.

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

See Also

For more information see Object.

Examples

  setConstructorS3("MyClass", function() {
    extend(Object(), "MyClass")
  })

  setMethodS3("finalize", "MyClass", function(this) {
    cat(as.character(this), "is about to be removed from the memory!\n")
  })

  o <- MyClass()
  o <- MyClass()
  o <- MyClass()
  o <- MyClass()
  gc()

  ## Not run: 
  MyClass: 0x01BE602C is about to be removed from the memory!
  MyClass: 0x01BFF634 is about to be removed from the memory!
  MyClass: 0x01C13584 is about to be removed from the memory!
           used (Mb) gc trigger (Mb)
  Ncells 229903  6.2     467875 12.5
  Vcells  53725  0.5     786432  6.0
  
## End(Not run)

  rm(o)
  ## Not run: 
  MyClass: 0x01C578B0 is about to be removed from the memory!
           used (Mb) gc trigger (Mb)
  Ncells 229903  6.1     467875 12.3
  Vcells  53725  0.5     786432  6.0
  
## End(Not run)

[Package R.oo version 1.6.5 Index]