Re: [Rd] [External] The finalizer of the externalPtr does not work when closing R?

2020-04-03 Thread Wang Jiefei
Thanks for all your guys responses! It is amazing to get so many answers in a few minutes! My package needs to handle the shared memory so the finalizer does cause memory leaking. The Ex version should be my solution for that. Thanks for all your help. Best Jiefei On Fri, Apr 3, 2020, 9:14 PM w

Re: [Rd] [External] The finalizer of the externalPtr does not work when closing R?

2020-04-03 Thread luke-tierney
Use R_RegisterFinalizerEx in your C code. See https://cran.r-project.org/doc/manuals/r-release/R-exts.html#External-pointers-and-weak-references This still gives you only "best effort"; for anything stronger you would need a different approach. In general, finalizers should only be used as a ba

Re: [Rd] The finalizer of the externalPtr does not work when closing R?

2020-04-03 Thread Tomas Kalibera
+ 5.13 of Writing R Extensions Tomas On 4/3/20 3:04 PM, Gábor Csárdi wrote: See R_RegisterCFinalizerEx() and set onexit to nonzero. Here: https://github.com/wch/r-source/blob/9353ddfa8d30069ad8975e0364307d710f2488d5/src/include/Rinternals.h#L1279-L1280 Gabor On Fri, Apr 3, 2020 at 1:56 PM Wang

Re: [Rd] The finalizer of the externalPtr does not work when closing R?

2020-04-03 Thread Gábor Csárdi
See R_RegisterCFinalizerEx() and set onexit to nonzero. Here: https://github.com/wch/r-source/blob/9353ddfa8d30069ad8975e0364307d710f2488d5/src/include/Rinternals.h#L1279-L1280 Gabor On Fri, Apr 3, 2020 at 1:56 PM Wang Jiefei wrote: > > Hi all, > > I found that the finalizer of the externalPtr i

[Rd] The finalizer of the externalPtr does not work when closing R?

2020-04-03 Thread Wang Jiefei
Hi all, I found that the finalizer of the externalPtr is not called when R is quitting. However, manually calling GC() works fine. This behavior is observed on devel R 2020-04-02 r78142 on Win and R 3.6.3 on Ubuntu. I make a reproducible package here: https://github.com/Jiefei-Wang/example Here