Skip to content
Prev 49203 / 63424 Next

proper use of reg.finalizer to close connections

Hmmm, I guess you will want to put the actual objects that represent
the connections into the environment, at least this seems to be the
easiest to me. Btw. you need ls() to list the contents of an
environment, instead of names(). E.g.

e <- new.env()
e$foo <- 10
e$bar <- "aaa"
names(e)
#> NULL
ls(e)
#> [1] "bar" "foo"
reg.finalizer(e, function(x) { print(ls(x)) })
#> NULL
rm(e)
gc()
#> [1] "bar" "foo"
#>           used (Mb) gc trigger  (Mb) max used  (Mb)
#> Ncells 1528877 81.7    2564037 137.0  2564037 137.0
#> Vcells 3752538 28.7    7930384  60.6  7930356  60.6

More precisely, you probably want to represent each connection as a
separate environment, with its own finalizer. Hope this helps,
Gabor
On Sun, Oct 26, 2014 at 9:49 PM, Murat Tasan <mmuurr at gmail.com> wrote: