Closing connection on gc()
DavorJ opened this issue · 1 comments
DavorJ commented
I wonder why there is no public method similar to the following:
finalize = function() {
self$close()
}
During gc()
the finalize()
function would be executed.
Is closing the connection this way left out on purpose for some reason? I am not sure the underlying C code is closing the connection during destruction.
DavorJ commented
Further more, it is stated in the vignette that:
As long as a WebSocket object has an open connection, it will not be eligible for garbage collection [...].
But it seems you don't even need an open connection:
WebSocketExt <- R6::R6Class(
classname = 'WebSocketExt',
inherit = websocket::WebSocket,
public = list(
# initialize = function(...) {},
finalize = function() {
message('Cleaning up.')
self$close()
}
)
)
wse <- WebSocketExt$new(.URI, autoConnect = FALSE)
rm(wse)
gc()
In this case, gc()
doesn't destruct the object. finalize()
will only be executed after ending the R session. I don't think this is as intended, no?
PS Tested on R 3.6.3 and 4.0.5.