Skip to content
Back to formatted view

Raw Message

Message-ID: <20250905125208.1540e379@arachnoid>
Date: 2025-09-05T09:52:08Z
From: Ivan Krylov
Subject: Processing repeated images and memory recovery by GC
In-Reply-To: <CAMCTF-er2CPOB+_6NQFbbWU-SG7yfYqUQHWiiH__z-v7LvOVeg@mail.gmail.com>

? Thu, 4 Sep 2025 17:16:15 -0400
Steve Rowley via R-help <r-help at r-project.org> ?????:

> Then I use erase.screen() to erase the previous
> image, use plot() to set up a plotting area, and display the image
> with rasterImage().  

erase.screen() works by drawing a background-coloured rectangle over
the plot, so the previous images remain in the display list despite
being completely over-painted:

dev.new(bg='white')
split.screen(c(1,2))
# [1] 1 2
recordPlot() |> object.size()
# 57584 bytes
for (i in 1:2) {
 screen(i, FALSE)
 plot(0:1, 0:1, type = 'n')
 rasterImage(as.raster(matrix(runif(2^20), 2^10)), 0, 0, 1, 1)
}
recordPlot() |> object.size() |> print(units = 'Mb')
# 16.2 Mb
for (i in 1:2) {
 erase.screen(i)
 screen(i, FALSE)
 plot(0:1, 0:1, type = 'n')
 rasterImage(as.raster(matrix(runif(2^20), 2^10)), 0, 0, 1, 1)
}
recordPlot() |> object.size() |> print(units = 'Mb')
# 32.3 Mb

How much slower would it be to maintain your own "display list" of
images and redraw the plot from scratch (e.g. using layout()) every
time you change it?

-- 
Best regards,
Ivan