r-tmap / r-tmap/tmap

tm_animate memory issue

Open
#1,237 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Animation
Dominant language
R
Stars
907
Forks
123
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied sf/tmap script and observing memory growth through tm_animate_fast and tmap_animation, both named entry points in the report. Compare behavior with TMP redirected to disk and identify where frame generation or animation handling retains memory. Done means the reproduction no longer steadily grows until “recursive gc invocation” during the reported animation.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.