On 5/23/23 20:29, Peter Meilstrup wrote:
R developers, I am trying to track down a memory leak in my R package. I have a complex object O which comprises a lot of closures and such. Among which, the object uses an environment E to perform computations and keep intermediate values in. When O closes/finishes with its task it nulls out its reference to E so that that intermediate data can be garbage collected; I've verified that it does null the reference. However, it seems there is another reference to E floating around. I can tell because I can ask O to put a large array in E, then tell O to close, which nulls the reference to E, but then if I serialize(O, ascii=TRUE) I can still see the array in the output. Dangling references to E could come from a closure created in E, or an unforced promise from a function call evaluated in E that created a closure I still have a reference to, or, ... my question is how do I locate the reference? Is there a way to scan the workspace for objects that refer to a given object? Or is there a tool that will unpack/explain serialize()'s .rds format in a more human-readable way so that I can tell where the reference to E occurs?
Maybe you could re-use my script used for finding a particular string in the R heap (captured temporary installation directory name during staged installation). It should be fairly easy to modify it to look for a particular environment object.
Best Tomas https://github.com/kalibera/rstagedinst/blob/master/sicheck.R https://blog.r-project.org/2019/02/14/staged-install/index.html
Peter ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel