r-lib/pkgload

Consider calling gc() in load_all?

thk686 opened this issue · 2 comments

When working with external pointers that have registered finalizers, things can get a bit dicey with load_all. This is quite hard to demonstrate and debug. But I put print callbacks into my finalizers and I see objects getting garbage collected after the call to load_all. A few calls to gc() (unfortunately there does not seem to be a recursive gc option when pointers are protected by other objects) at the top of that function would help avoid this. Or you might consider not saving and restoring external pointers.

On second look, I see that there is a call-out to pkgload package. I don't know where the best place to try to run finalizers might be. The code is fairly involved, but as far as I can tell, it does not seem that the .onUnload or .onDetatch hooks are called. If not, that or some other hook could be a solution for package devs.

The previously loaded namespaces can linger for a long time or even forever after a load_all().

Why do you need to call finalizers when loading a package?

Sorry I don't think we want to guarantee finalisers to be run after load_all().

Regarding the unload hook, it's being discussed in #253.