Title: [BUG]: Memory Leak - Heatmap redraws continuously grow Chromium renderer memory via unique PNG `data:` URLs · Issue #8097 · plotly/plotly.js · GitHub
Open Graph Title: [BUG]: Memory Leak - Heatmap redraws continuously grow Chromium renderer memory via unique PNG `data:` URLs · Issue #8097 · plotly/plotly.js
X Title: [BUG]: Memory Leak - Heatmap redraws continuously grow Chromium renderer memory via unique PNG `data:` URLs · Issue #8097 · plotly/plotly.js
Description: Description Every heatmap redraw sets the trace's SVG
Open Graph Description: Description Every heatmap redraw sets the trace's SVG
X Description: Description Every heatmap redraw sets the trace's SVG <image> to a fresh canvas.toDataURL('image/png') (src/traces/heatmap/plot.js#L369). In Chromium, these distinct data-URL imag...
Opengraph URL: https://github.com/plotly/plotly.js/issues/8097
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG]: Memory Leak - Heatmap redraws continuously grow Chromium renderer memory via unique PNG `data:` URLs","articleBody":"## Description\n\nEvery heatmap redraw sets the trace's SVG `\u003cimage>` to a fresh `canvas.toDataURL('image/png')` ([`src/traces/heatmap/plot.js#L369`](https://github.com/plotly/plotly.js/blob/v4.1.1/src/traces/heatmap/plot.js#L369)). In Chromium, these distinct data-URL image resources remain retained in the document's image/resource cache for the lifetime of the page. A heatmap that is updated repeatedly (e.g., live data, `Plotly.react` in a loop) therefore grows the renderer's native memory by approximately one image resource per update. The memory is not reclaimed while the page remains alive. The JS heap stays flat, so heap snapshots don't show the growth.\n\nWe hit this in a desktop app (Edge WebView2) that plots live measurements. A heatmap, refreshing about once a second, took the renderer from 1.2 GB to 13.5 GB in 3 h 13 min, after which it was killed with `RenderProcessExited, Reason=OutOfMemory`.\n\n## Screenshots/Video\n\nNo video, but here is the memory of the example below, measured over 10 minutes with plotly.js 4.1.1 (un-minified) in Chromium 153.0.8010.12 on Windows 11. A full GC was forced before each sample (`--js-flags=--expose-gc`, `gc()` twice); \"renderer\" is the renderer process's private memory.\n\n| Time | Updates | Renderer, as is | Renderer, with the workaround in Notes | JS heap (both) |\n| --- | ---: | ---: | ---: | ---: |\n| 0 min | 1 | 162 MB | 164 MB | 32 MB |\n| 1 min | ~160 | 391 MB | 388 MB | 32 MB |\n| 2 min | ~300 | 389 MB | 388 MB | 32 MB |\n| 4 min | ~550 | 660 MB | 549 MB | 32 MB |\n| 6 min | ~790 | 899 MB | 651 MB | 32 MB |\n| 8 min | ~1000 | 1090 MB | 705 MB | 32 MB |\n| 10 min | ~1300 | **1123 MB** | **483 MB** | 32 MB |\n\nAs is, the renderer gains about 0.7 MB per update, roughly 100 MB per minute at ~2.2 updates/s. With the workaround, memory remains bounded and can fall back substantially after reclamation. 4.0.0 behaves the same (139 -> 1310 MB over the same 10 minutes).\n\n## Steps to reproduce\n\n1. Save this as an HTML file and open it in Chrome or Edge:\n\n```html\n\u003c!doctype html>\n\u003cmeta charset=\"utf-8\">\n\u003cdiv id=\"plot\" style=\"width:900px;height:700px\">\u003c/div>\n\u003cscript src=\"https://cdn.plot.ly/plotly-4.1.1.js\">\u003c/script>\n\u003cscript>\n // A \"live\" 1000x1000 heatmap: one more row is filled on every update.\n const N = 1000;\n let frame = 0;\n\n function nextZ() {\n frame++;\n const z = [];\n for (let r = 0; r \u003c N; r++) {\n const row = new Array(N);\n for (let c = 0; c \u003c N; c++) {\n row[c] =\n r \u003c= frame % N\n ? Math.sin(r / 30 + c / 50 + frame / 10)\n : NaN;\n }\n z.push(row);\n }\n return z;\n }\n\n async function update() {\n await Plotly.react(\"plot\", [{ type: \"heatmap\", z: nextZ() }]);\n setTimeout(update, 250);\n }\n\n update();\n\u003c/script>\n```\n\n2. Open the browser's Task Manager (Shift+Esc) and watch the tab's memory footprint (keep the tab/window in foreground).\n3. It climbs by roughly 100 MB a minute and does not come back down, while the JS heap (DevTools > Memory) stays at ~30 MB.\n\n### Notes\n\n**It's the data URLs, not Plotly's data handling.** I repeated the test without Plotly, using one SVG `\u003cimage>` whose `href` is set to a new 1580×1580 PNG on every update:\n- **A data URL each time:** renderer 186 → 1220 MB over 600 updates.\n- **The same PNG as a blob URL, revoking the previous one:** flat at ~500 MB.\n- **Replacing the `\u003cimage>` element instead of updating it:** still grows.\n- **Swapping the data URL for a blob URL one animation frame later:** still grows, because the data URL is loaded as soon as it is set.\n\n**Real-world numbers.** Edge WebView2 154.0.4258.37 with a 1580×1580 heatmap (2.5M points) updated about once a second. The renderer grew ~3.8 GB/h and crashed after 3 h 13 min at 13.5 GB, while the page's JS heap stayed between 0.45 and 1 GB.\n\n### Suggested fix\nIn `heatmap/plot.js`, use a blob URL for on-screen rendering and revoke the previous one. Keep the data URL for `toImage`, which serializes the SVG, where a `blob:` URL would not survive:\n\n```js\n// Instead of: 'xlink:href': canvas.toDataURL('image/png')\nif (gd._context._exportedPlot) {\n image3.attr('xlink:href', canvas.toDataURL('image/png'));\n} else {\n canvas.toBlob(function(blob) {\n var node = image3.node();\n if (!node || !blob) return;\n var url = URL.createObjectURL(blob);\n if (node._blobUrl) URL.revokeObjectURL(node._blobUrl);\n node._blobUrl = url;\n node.setAttributeNS(xmlnsNamespaces.xlink, 'xlink:href', url);\n });\n}\n```\n\nThe last blob URL should also be revoked when the image is removed or the plot is purged. `toBlob` is asynchronous, so the previous image stays on screen until the new one is ready, which looks the same as today. A synchronous alternative is to decode the data URL into a `Blob` and use `URL.createObjectURL`, which is what our workaround does.\n\nI haven't built or tested this patch inside plotly.js, but it works for us in our app.\n\n`traces/image/plot.js` builds its `href` the same way and probably has the same problem; I haven't measured it.\n\n### Workaround\nSwap each new data URL for a blob URL from a `MutationObserver` on the plot. It must happen in the same task as Plotly's update; in my testing, waiting until the next animation frame is already too late:\n\n```js\nconst blobs = new WeakMap();\nnew MutationObserver((records) => {\n for (const { target, attributeName, attributeNamespace } of records) {\n if (attributeName !== \"href\" || target.localName !== \"image\") continue;\n const href = target.getAttributeNS(attributeNamespace, \"href\");\n if (!href?.startsWith(\"data:image/png;base64,\")) continue;\n const bin = atob(href.slice(22));\n const bytes = new Uint8Array(bin.length);\n for (let i = 0; i \u003c bin.length; i++) bytes[i] = bin.charCodeAt(i);\n const url = URL.createObjectURL(new Blob([bytes], { type: \"image/png\" }));\n target.setAttributeNS(attributeNamespace, attributeNamespace ? \"xlink:href\" : \"href\", url);\n if (blobs.has(target)) URL.revokeObjectURL(blobs.get(target));\n blobs.set(target, url);\n }\n // No attributeFilter: it never matches namespaced attributes such as xlink:href.\n}).observe(document.getElementById(\"plot\"), { attributes: true, subtree: true });\n```\n\n### Environment\n- plotly.js 4.1.1 and 4.0.0\n- Chromium 153.0.8010.12 and Edge WebView2 154.0.4258.37\n- Windows 11 (build 26200).\n\nNot tested in Firefox or Safari.\n","author":{"url":"https://github.com/JeS24","@type":"Person","name":"JeS24"},"datePublished":"2026-10-01T14:52:33Z","url":"https://github.com/plotly/plotly.js/issues/8097"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fdb81279-159e-e3c1-8ddd-984df237073e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B34A:2270F4:28700A5:35B5CC8:6B01B081 |
| html-safe-nonce | 5266f4ef6eaab26360a26cda28e4c00f5815e744f0af3c44ed713ffefa505307 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzRBOjIyNzBGNDoyODcwMEE1OjM1QjVDQzg6NkIwMUIwODEiLCJ2aXNpdG9yX2lkIjoiNDE5MjQzNjY5NTAyMTQ0NjQxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 48c784efba4aee0e8a94af2a8b5c199ffc59ac10f128b9ea9d0de5ba6bb82eae |
| hovercard-subject-tag | issue:5664183467 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/plotly/plotly.js/8097/issue_layout |
| twitter:image | https://opengraph.githubassets.com/981c86a5b5ea1413baa5e712182f75c4ffc8307d65032bf421966c929a15156f/plotly/plotly.js/issues/8097 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/981c86a5b5ea1413baa5e712182f75c4ffc8307d65032bf421966c929a15156f/plotly/plotly.js/issues/8097 |
| og:image:alt | Description Every heatmap redraw sets the trace's SVG |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JeS24 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/plotly/plotly.js git https://github.com/plotly/plotly.js.git |
| octolytics-dimension-user_id | 5997976 |
| octolytics-dimension-user_login | plotly |
| octolytics-dimension-repository_id | 45646037 |
| octolytics-dimension-repository_nwo | plotly/plotly.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 45646037 |
| octolytics-dimension-repository_network_root_nwo | plotly/plotly.js |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width