R.oo (version 1.20.0)

gc.Object: Deprecated: Clear cached fields and calls the garbage collector

Description

Deprecated: Clear cached fields and calls the garbage collector. Cached fields are set to NULL when cleared.

This method is deprecated. Please use clearCache(..., gc=TRUE) instead.

Usage

"gc"(this, ...)

Arguments

...
Not used.

Value

Returns nothing.

See Also

To clear the fields without calling the garbage collector, see *clearCache(). For more information see Object.

Examples

Run this code
setConstructorS3("CachedObject", function(...) {
  extend(Object(), "CachedObject",
    ...
  )
})

setMethodS3("as.character", "CachedObject", function(this, ...) {
  s <- NextMethod("as.character", this, ...)
  s <- sprintf("%s. RAM: %.2fkb.", s, objectSize(this)/1024)
  s
})

obj <- CachedObject(a=1, b=1:10^5, "cached:c"=1:10^6)
print(ll(obj))
print(obj) # [1] "CachedObject: 0x02466E28. RAM: 4297.16kb."

clearCache(obj, gc=TRUE)    # Clear all cached fields
print(ll(obj))
print(obj) # [1] "CachedObject: 0x02466E28. RAM: 391.05kb."

Run the code above in your browser using DataCamp Workspace