[R] Processing repeated images and memory recovery by GC
Ivan Krylov
|kry|ov @end|ng |rom d|@root@org
Fri Sep 5 11:52:08 CEST 2025
В Thu, 4 Sep 2025 17:16:15 -0400
Steve Rowley via R-help <r-help using 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
More information about the R-help
mailing list