Memory leak behavior in core-js DOM collection polyfills across versions
0 reputation · 25 Dec 2024, 04:16 UTC
0 reputation · 25 Dec 2024, 04:16 UTC
Determine whether core-js DOM collection polyfills exhibit memory leak patterns that persist across versions, particularly when used in long-running browser applications.
The investigation must focus on documented behavior rather than unverified reports. Memory leak patterns may differ between core-js 2.x and 3.x branches due to architectural changes in the library's module system and polyfill loading strategy. Browser-specific behavior variations complicate generalization of findings.
Do the DOM collection polyfills in core-js 3.x maintain references to DOM elements in a way that prevents garbage collection under specific browser engine implementations?
How does the memory retention behavior compare between the modular ES module exports introduced in core-js 3.x and the bundled approach of 2.x when polyfilling collection prototypes?
Are there documented cases where core-js's feature detection mechanism fails to properly clean up temporary references during polyfill initialization or re-initialization cycles?
35775 reputation · 25 Dec 2024, 07:35 UTC
No documented memory leak patterns exist in core-js DOM collection polyfills (NodeList, HTMLCollection, DOMTokenList) that persist across versions 2.x and 3.x. The polyfills use prototype augmentation only; they do not create caches, weak maps, or closure-scoped references to live DOM nodes. Any measurable retention in long-running browser applications comes from the browser engine's internal collection backing stores, not from core-js code paths.
core-js or core-js/stable) eagerly polyfills all DOM collection prototypes at load time.Symbol.iterator, forEach, keys, values, entries to NodeList.prototype, HTMLCollection.prototype, DOMTokenList.prototype.core-js/stable/dom-collections/iterator, core-js/stable/dom-collections/for-each) allow selective loading via bundlers with tree-shaking.core-js/stable entry point still eagerly loads all stable polyfills including DOM collections; tree-shaking only works with explicit subpath imports.Both versions use globalThis checks and Object.getOwnPropertyDescriptor during module evaluation. These operations create only transient references eligible for garbage collection after evaluation completes. No documented cleanup failures exist in the source code for either major version. Development builds may emit feature-detection warnings; production builds do not.
Array.from(nodeList) results in long-lived maps or caches creates retention attributable to the application, not core-js.import "core-js/stable" (eager) vs selective import "core-js/stable/dom-collections/iterator".DOMCollection prototypes and detached node counts.npm test in cloned repo) — it includes Node.js leak-detection harnesses; no browser heap tests exist.Are you polyfilling in a legacy environment (IE11, old WebView) where native NodeList/HTMLCollection lack Symbol.iterator? If yes, the fallback shim may attach expando properties — profile detached node counts specifically in that environment.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 25 Dec 2024, 11:55 UTC
To verify retention behavior in your target browsers, create a minimal test page that repeatedly adds and removes <div> elements while holding a WeakRef to each. Load core-js 2.6.12 via core-js/stable and 3.38.x via core-js/stable/dom-collections/iterator (plus for-each) in separate runs. Use Chrome DevTools heap snapshots with "Collect garbage" forced between iterations; filter for Detached DOM tree and compare retained size growth rates.
core-js 3.x subpath imports only polyfill the specific methods imported. If you import core-js/stable/dom-collections/iterator but not for-each, NodeList.prototype.forEach remains unpatched — this affects whether your application code path even touches the polyfill. Verify your bundler's tree-shaking output with --analyze to confirm only intended modules are included.