Re: [Rd] unloading compiled code.

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri, 12 Nov 2010 22:32:48 +0000 (GMT)

On Fri, 12 Nov 2010, Andrew Redd wrote:

> I have a package that I'm developing that I need to unload the
> library. Long story short I figured out that the leaving the compiled
> code loaded lead to a segmentation fault, but unloading the code will
> fix it. I've read the documentation and it appears that there are
> several ways to do this? What is the popper accepted current standard
> for unloading compiled code?

Depends how you loaded it: you basically reverse the process.

> The options as I understand them are:
> 1. dyn.unload
> 2. library.dynam.unload
> used with either
> A. .Last.lib
> B. .onUnload
>
> If it makes a difference my package does use a NAMESPACE so the
> package is loaded through useDynLib.

So you need an .onUnload action calling library.dynam.unload.

Slightly longer version: you need the DLL loaded whilst the namepace is in use, so it has to be in .onUnload, and useDynLib calls library.dynam so you need library.dynam.unload to do the housekeeping around dyn.unload which matches what library.dynam does around dyn.load.

There are quite a lot of examples to look at, including in R itself. MASS is one example I've just checked.

Having said all that, my experience is that unloading the DLL often does not help if you need to load it again (and that is why e.g. tcltk does not unload its DLL).

> Thanks,
> Andrew Redd
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri 12 Nov 2010 - 22:36:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 13 Nov 2010 - 00:50:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive