fix(devtools): clean up removed directive entries in IdentityTracker to prevent memory leak#67795
Open
AleksanderBodurri wants to merge 1 commit intoangular:mainfrom
Open
Conversation
…to prevent memory leak The IdentityTracker singleton never deleted entries from its internal maps (_currentDirectiveId, _currentDirectivePosition, isComponent) for destroyed directives. This caused the maps to grow monotonically for the entire DevTools session, retaining references to destroyed component instances and preventing garbage collection. The cleanup was intentionally commented out because the profiler needs to resolve IDs and positions of removed components during recording. Introduce `setProfilingActive()` to gate cleanup: when profiling is inactive, removed entries are deleted immediately during `index()`. When profiling is active, removals are deferred into a `_pendingRemovals` set and flushed once profiling stops via `capture.ts` start/stop calls.
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.
The IdentityTracker singleton never deleted entries from its internal maps (_currentDirectiveId, _currentDirectivePosition, isComponent) for destroyed directives. This caused the maps to grow monotonically for the entire DevTools session, retaining references to destroyed component instances and preventing garbage collection.
The cleanup was intentionally commented out because the profiler needs to resolve IDs and positions of removed components during recording.
Introduce
setProfilingActive()to gate cleanup: when profiling is inactive, removed entries are deleted immediately duringindex(). When profiling is active, removals are deferred into a_pendingRemovalsset and flushed once profiling stops viacapture.tsstart/stop calls.