Skip to content

fix(devtools): clean up removed directive entries in IdentityTracker to prevent memory leak#67795

Open
AleksanderBodurri wants to merge 1 commit intoangular:mainfrom
AleksanderBodurri:fix/identity-tracker-memory-leak
Open

fix(devtools): clean up removed directive entries in IdentityTracker to prevent memory leak#67795
AleksanderBodurri wants to merge 1 commit intoangular:mainfrom
AleksanderBodurri:fix/identity-tracker-memory-leak

Conversation

@AleksanderBodurri
Copy link
Member

@AleksanderBodurri AleksanderBodurri commented Mar 23, 2026

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.

…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.
@ngbot ngbot bot added this to the Backlog milestone Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant