fix(ResizeWatcher): Fix memory leak with ResizeWatcher #144
Open
sankhesh wants to merge 4 commits intoKitware:masterfrom
Open
fix(ResizeWatcher): Fix memory leak with ResizeWatcher #144sankhesh wants to merge 4 commits intoKitware:masterfrom
sankhesh wants to merge 4 commits intoKitware:masterfrom
Conversation
Adds a test to detect memory leaks in ResizeWatcher when callbacks are removed. This test verifies that DOM elements are properly cleaned up.
Unobserves and deletes elements from the callbacks map when they are no longer needed to resolve memory leaks from stale observer entries. Co-authored-by: Will McCambley <willmccambley@gmail.com>
Corrects peer dependency flags across dependencies and removes ts-node and cosmiconfig from package-lock.json files.
There was a problem hiding this comment.
Pull request overview
This PR addresses a ResizeWatcher memory leak by ensuring elements are fully removed from internal tracking when no callbacks remain, and adds a usage demo to help reproduce/verify the leak behavior over repeated mount/unmount cycles.
Changes:
- Fix
ResizeWatcher.unwatch()to delete element entries from the callbacks map when the last callback is removed. - Add a
ResizeWatcherLeakTestusage demo and exposeResizeWatcherContextfrom the library to display tracked-element counts. - Update lockfiles (notably the root
package-lock.json).
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/utils/ResizeWatcher.ts |
Fixes leak by deleting tracked elements when no callbacks remain; adds a tracked-element count helper. |
src/index.ts |
Exposes ResizeWatcherContext and related types from the public entrypoint. |
usage/src/Tests/ResizeWatcherLeakTest.jsx |
Adds a manual/visual repro test for the leak via repeated view cycling and tracked-element count display. |
usage/src/App.jsx |
Registers the new usage demo in the demo selector. |
usage/package-lock.json |
Lockfile updated due to dependency tree changes/regeneration. |
package-lock.json |
Lockfile updated, but currently contains invalid version fields (must be fixed). |
Files not reviewed (1)
- usage/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add getTrackedElementCount as an optional method on IResizeWatcher so TS consumers can call it via the context without casting; keeping it optional preserves the freedom for alternate implementations to not expose it. - Wire dependency array on the leak test's tracked-count effect so it only re-reads when the watcher or cycle count changes, instead of on every render. - Track the cycle() setTimeout in a ref and clear it on unmount so a pending timer cannot setState on an unmounted component if the demo is swapped within 200ms.
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.
Before
After