Skip to content

Memory leak: initial route is stuck in "Detached node" state and never freed #66087

@NateRadebaugh

Description

@NateRadebaugh

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

router

Is this a regression?

No

Description

When opening a URL in the browser, we can use Chrome DevTools Memory tab to snapshot Detached elements. When navigating to subsequent page using navigation above, the initial component remains in memory and is never freed.

Example app: https://stackblitz.com/edit/stackblitz-starters-nt5jurhb?file=src%2Fmain.ts

Repro steps:

  1. Start on the /example1 URL. See "Example 1" page. (good)
  2. Open Chrome DevTools > Memory > Detached elements
  3. [Take snapshot] and see there are no detached nodes (good)
  4. Navigate to "Example 2" via the top navigation. See "Example 2" page. (good)
  5. [Take snapshot]

Expected:
There should be no "Detached elements" listed

Actual:
The app-example1 node is showing as detached.

Image

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-nt5jurhb?file=src%2Fmain.ts

Please provide the exception or error you saw

Also I have no idea how to debug this or things like this when they come up. Who has the handle and how can I clear it? I've already tried manually running GC so that doesn't seem to be the issue.

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

Angular CLI       : 21.0.2
Angular           : 21.0.3
Node.js           : 20.19.1
Package Manager   : npm 10.8.2
Operating System  : linux x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/animations       │ 21.0.3            │ ^21.0.3           │
│ @angular/build            │ 21.0.2            │ ^21.0.2           │
│ @angular/cli              │ 21.0.2            │ ^21.0.2           │
│ @angular/common           │ 21.0.3            │ ^21.0.3           │
│ @angular/compiler         │ 21.0.3            │ ^21.0.3           │
│ @angular/compiler-cli     │ 21.0.3            │ ^21.0.3           │
│ @angular/core             │ 21.0.3            │ ^21.0.3           │
│ @angular/forms            │ 21.0.3            │ ^21.0.3           │
│ @angular/platform-browser │ 21.0.3            │ ^21.0.3           │
│ @angular/router           │ 21.0.3            │ ^21.0.3           │
│ rxjs                      │ 7.8.2             │ ^7.8.1            │
│ typescript                │ 5.9.3             │ ^5.9.3            │
│ zone.js                   │ 0.16.0            │ ^0.16.0           │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions