Skip to content
Prev 398142 / 398506 Next

Processing repeated images and memory recovery by GC

Jan raises an interesting point. In R, the ggplot2 object can incorporate some of the data you are asking it to plot. So code like:

P <- ggplot2(...) + ... 

The above will save a copy or perhaps "pointer" to the data that remains in memory if not removed even if the original is removed. And thee can be a hidden gotcha as lines of code run in the R interpreter are saved in .Last.value, albeit that is overwritten after each line of code.



-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Jan van der Laan
Sent: Friday, September 5, 2025 4:21 AM
To: r-help at r-project.org
Subject: Re: [R] Processing repeated images and memory recovery by GC
On 05-09-2025 01:24, Jeff Newmiller via R-help wrote:

            
And often writing such a minimal example helps in pinpointing the issue 
quite often leading to a solution.

You could start by stripping down your current code. Remove all plotting 
commands: does the problem still exist then it is probably in reading or 
cleaning up the image rasters. Is it just for png's or for all image 
formats? Etc. Another way is 'bottom up': write a script that reads 
images and does nothing with them; does the problem happen there? Then 
start adding stuff until the issue occurs again.

Could it be that you keep opening up new graphics devices without 
closing them? Also split.screen creates a kind of devices that should be 
closed.

HTHT,
Jan
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.