Skip to content

fix(core): destroy CanvasContext on finalize to prevent memory leak#10356

Open
LeLunZ wants to merge 2 commits into
visgl:masterfrom
LeLunZ:master
Open

fix(core): destroy CanvasContext on finalize to prevent memory leak#10356
LeLunZ wants to merge 2 commits into
visgl:masterfrom
LeLunZ:master

Conversation

@LeLunZ

@LeLunZ LeLunZ commented Jun 8, 2026

Copy link
Copy Markdown

Closes #10355

Background

When unmounting a Deck instance (both standalone and via wrappers like MapboxOverlay), a memory leak occurs where detached DOM nodes (the <canvas>) and Deck instances are never garbage collected.

Previously, Deck.finalize() simply dropped the reference to this._canvasContext. Because this._canvasContext?.destroy() was never explicitly called, luma.gl's Surface superclass never ran _stopObservers(). As a result, the ResizeObserver and matchMedia listeners remained permanently bound to the Window, creating a strong GC root that kept the detached canvas and Deck instance alive indefinitely.

Note: This was originally observed using MapboxOverlay.

Change List

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Memory Leak: Deck.finalize() drops CanvasContext reference instead of destroying it, leaving ResizeObserver attached

1 participant