Memory leak (loading VGAM package)

Issue #211 invalid
ra_ created an issue

Loading the VGAM package allocates memory that can not be freed any more. If the package is a loaded in worker threads using Python's multiprocessing library, every worker thread allocates memory that can not be freed, despite explicitly clearing R's memory space and running Python's garbage collector.

Attached is code that triggers the bug described.

Comments (3)

  1. Laurent Gautier

    In essence the rpy2 code in your example is:

    # import R package VGAM
    vgam = importr('VGAM')
    # delete Python namespace 'vgam'
    del vgam

    The first line is importing the R package in the embedded R, and is then creating a Python namespace in which Python objects exposing the R objects in the module a created. The second line is deleting that Python namespace, but is not unloading the package on the R side. The R code do "unload" packages is:


    That code can be called from rpy2 if you wish to, but note that dynamically linked library may or may not be "unloaded" (I have not checked this in a long time).

  2. ra_ reporter


    r_base = importr('base')

    does the trick, as you wrote (even without detaching the base package, memory consumption does not increase). This is great - thank you!

    Although I understand the technical reasons, I consider the required call of "detach" not intuitive. Hence, I think it might be worth mentioning in the documentation.

  3. Log in to comment