Skip to content
Prev 25223 / 63424 Next

Possible changes to connections

In a previous version of the 'filehash' package, the 'filehashDB1'
class had a slot for an open connection corresponding to the database
file.  I quickly learned that if the R object ever got removed or
reassigned I was left hanging with an open file connection.

If I remember correctly, I resorted to creating an environment in the
R object which stored the connection number for the the database file
connection.  Then I registered a finalizer for that environment which
grabbed the connection via 'getConnection' and then closed the
connection.

I eventually abandoned this approach since it was error-prone and I
often ran into strange difficult-to-reproduce situations where the R
object representing the database had been removed but the file
connection was still open because garbage collection had not yet
occurred.  I would have very much preferred a system where the file
connection was automatically closed once any references to it were
gone.

-roger
On 5/30/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote: