Skip to content

Event replay memory leak #59261

@arturovt

Description

@arturovt

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

Elements are not being garbage collected properly when the app is destroyed because they are captured inside the early event contract event info list. When calling appRef.destroy(), we can capture the heap snapshot and observe the detached <app-root />, which cannot be garbage collected:

Image

Please provide a link to a minimal reproduction of the bug

https://github.com/arturovt/ng-issue-event-replay-leak

Please provide the exception or error you saw

Elements are captured in that part of the code:

const q: EventInfo[] = [];
const d = (eventInfo: EventInfo) => {
q.push(eventInfo);
};
const h = (event: Event) => {
d(
createEventInfoFromParameters(
event.type,
event,
event.target as Element,
container,
Date.now(),
),
);
};

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.0.4
Node: 20.11.1
Package Manager: yarn 1.22.22
OS: linux x64

Angular: 19.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.4
@angular-devkit/build-angular   19.0.4
@angular-devkit/core            19.0.4
@angular-devkit/schematics      19.0.4
@schematics/angular             19.0.4
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimecore: event dispatchmemory leakIssue related to a memory leak

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions