I've been running into this problem in a few separate cases now and I'd like your input. In R, objects can be deleted or overwritten, but if they use Rcpp libraries, they will keep doing what they do.
For example, when connecting to a websocket using the websocket package:
ws<-WebSocket$new(paste0(gate,"/?v=6&encoding=json"),autoConnect=F)
ws$onMessage(function(event) {
print(event)
})
ws$connect()
The object ws is now my only way to control the websocket, and if it is deleted or overwritten, there is no way to make it disconnect except to restart R.
A similar issue when using the later package:
BumpUp<-function(.self){
.self$iter<-.self$iter+1
message("Valued bumped up to ",.self$iter)
if(.self$iter<10){
later::later(~.self$bump(),delay=1)
}
}
MakeTestObject<-setRefClass("testobject",fields=list(iter="numeric"),methods=list(bump=BumpUp))
testobj<-MakeTestObject(iter=0)
testobj$bump()
rm(testobj)
the loop associated with testobj continues to repeat, despite the fact that the object itself has been removed from memory.
Is there any way to make a reference class object check if it still exists in memory? More generally, is it possible for the object to know its name in memory?