Skip to content

tm_animate memory issue #1237

@wrobell

Description

@wrobell

Please consider

library(sf)
library(tmap)

bbox <- st_bbox(c(xmin=-6.2,
                  ymin=53.4,
                  xmax=-6.1,
                  ymax=53.5),
                crs=st_crs(4326))
cp <- st_as_sfc(bbox) |> st_centroid()
cx = st_coordinates(cp)[,1]
cy = st_coordinates(cp)[,2]

tb = seq(as.POSIXct('2025-08-01 10:00:00', tz='UTC'),
         as.POSIXct('2025-08-01 12:00:00', tz='UTC'),
         by=1)
angle = seq(0, 2 * pi, length.out=length(tb))

data = st_sf(tb=tb,
             geometry=st_sfc(lapply(seq_len(length(tb)),
                                    function(i) st_point(c(cx + 0.025 * cos(angle[i]),
                                                           cy + 0.025 * sin(angle[i])))),
                             crs=4326),
             angle=angle)

p = (tm_basemap('CartoDB.Positron')
     + tm_shape(data, bbox=bbox, crs=4326)
     + tm_dots('location', fill='red', fill_alpha=0.75)
     + tm_options(facet.max=3600 * 3)
     + tm_animate_fast('tb', fps=30))

tmap_animation(p, file='plot-traffic-bug.mp4', width=1024, height=1024)

Running this script you can see memory usage steadily grow and the execution fails with error

*** recursive gc invocation

This also happens when I set TMP=~/tmp, so PNG files (frames) are stored on a hard drive instead of tmpfs.

tmap 4.3, sf 1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions