Repository navigation
addGeotiff(): free a raster when its layer is removed - #111
Open
eliotmcintire wants to merge 1 commit into
Open
eliotmcintire wants to merge 1 commit into
eliotmcintire wants to merge 1 commit into
Conversation
Every addGeotiff() call added a click and a mousemove handler to the map, each holding the whole georaster, and never removed them. A layer replaced under the same layerId therefore stayed in memory, so an app stepping through rasters ran out of memory after a few hours. The handlers are now removed when their layer is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx3DXcxmq3mSxenWLiFbBD
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for leafem; I am a heavy user of it, through the map viewer in our SpaDES.shiny package. I only work in R, so I used Claude (an AI assistant) to find the cause and write the fix. This is a person and an AI working on it together.
When a Shiny app replaces a raster drawn with
addGeotiff(), the browser never frees the old one. An app that steps through maps with a time slider uses more memory at every step, and after a few hours the tab can no longer draw maps.Affects: apps that replace or remove
addGeotiff()layers now keep memory flat; clicking and hovering work as before.Technical details
Each
addGeotiff()call adds aclickand amousemovehandler to the map (georaster-binding.js, end ofaddGeotiff). Each handler holds the whole georaster, and nothing removes them, so a raster stays in memory after its layer is gone. This keeps the two handlers and removes them withmap.off()when the layer firesremove. Replacing a layer under the samelayerId,removeImage()andclearImages()all remove the layer, so each now frees it.Tested in headless Chromium with a minimal Shiny app that replaces a 1000×1000 layer through
leafletProxy()every 2 s, forcing garbage collection before each reading. Before: heap 66 → 423 MB in 80 s,mousemovehandlers 5 → 46. After: 40 MB throughout, 2 handlers. No errors were thrown in either run. The package has no JS tests, so none were added; I can share the test app.addCOG()has the same pattern. I left it alone because #110 changes that function; I can apply the same fix there or in a follow-up, whichever you prefer.Separately, and not fixed here: when layers are replaced faster than they draw (every 0.5 s with 1000×1000 rasters), georaster-layer-for-leaflet throws "Cannot read properties of null (reading 'reproj')". The browser console keeps each error, and each error keeps its layer, so memory grows that way too.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Lx3DXcxmq3mSxenWLiFbBD