Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFinalize method for cloned objects is executed in the wrong environment #167
Comments
|
It looks like # Start off by removing everything
rm(list = ls(all.names = TRUE))
gc()
happy <- R6::R6Class(
public = list(
foo = NULL,
initialize = function() {self$foo <- ":("},
happyify = function() {self$foo <- ":)"},
finalize = function() {cat("foo: ", self$foo, "\n")}
)
)
x <- happy$new()
y <- x$clone()
y$happyify()
rm(y)
gc()
rm(x)
gc()
#> foo: :(The reason that Lines 151 to 168 in 748bb60 |
|
Fixed by #180. |
When cloning an R6 object, it seems the finalize method still refers to the wrong Object. The code below should illustrate the problem quite well:
This could be related to #155 but I tried it with the newest dev version from github, and the problem still persisted :(
workarounds would also be welcome.