Skip to content

R extension memory leak detection question

3 messages · xiaoyan yu, Dirk Eddelbuettel

#
Thank you all for your help.
We embedded R in our program and found the memory in the process
accumulated while our expectation is that the memory will go down after
each R evaluation.
I started to write a test program with only a few lines of R embedded codes
and found the memory never went down even after R library is unloaded.
Please find more details in the readme and test program at
https://github.com/xiaoyanyuvt/RMemTest

Thanks,
Xiaoyan
On Fri, Mar 19, 2021 at 2:21 PM Lionel Henry <lionel at rstudio.com> wrote:

            

  
  
#
On 5 April 2021 at 18:27, xiaoyan yu wrote:
| Thank you all for your help.
| We embedded R in our program and found the memory in the process
| accumulated while our expectation is that the memory will go down after
| each R evaluation.
| I started to write a test program with only a few lines of R embedded codes
| and found the memory never went down even after R library is unloaded.
| Please find more details in the readme and test program at
| https://github.com/xiaoyanyuvt/RMemTest

You may find the projects RInside (for easily embedding R inside C++
programs) and littler (also embedding R, but using C only, for use in
lightweight cmdline applications) useful.  Those have existed for, give or
take, 10 and 15 years and have not proven to show memory leaks so I feel the
burden of proof is still on you.

Also I got your program to compile (after making the 'makefile' a bit more
general, and fixing two things upsetting current C++ compilers) but I am not
sure we really see memory consumption:

   edd at rob:~$ ps -fv $(pgrep -x foo)
       PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
   1456192 pts/9    S+     0:00      0     1  5890  1768  0.0 ./foo
   edd at rob:~$ ps -fv $(pgrep -x foo)
       PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
   1456192 pts/9    Sl+    0:00      0     1 1617174 9896  0.0 ./foo
   edd at rob:~$ 

Dirk
#
Thanks for your quick response. It is also surprising for us to notice the
memory accumulation when running our program since it has been years since
we developed our program.
Here is the memory status I observed from 15384k to 234208k to 242024k
without decreasing when running the test program.
[Before the first ENTER]$ps -aux | grep foo
xy 16985  0.0  0.0  *15384*  1312 pts/0    S+   00:09   0:00 ./foo
[After the first ENTER ]$ps -aux | grep foo
xy 16985  0.4  0.2 *234208* 42104 pts/0    S+   00:09   0:00 ./foo
[After the second ENTER and also before the program exit]$ps -aux | grep foo
xy    16985  0.1  0.2 *242024* 42244 pts/0    S+   00:09   0:00 ./foo

The test program is just a small simplified portion of our program. We
observed even more memory in use when running our program. We would like to
try to understand more of the memory life cycle of the embedded R.

Thanks,
Xiaoyan
On Mon, Apr 5, 2021 at 6:53 PM Dirk Eddelbuettel <edd at debian.org> wrote: