Skip to content

Seeing detached elements in a memory snapshot when I navigate from one route to another #58828

Closed as not planned
@Tomas-CloudIQ

Description

@Tomas-CloudIQ

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

router

Is this a regression?

No

Description

I am using Angular router module and trying to fix a memory leak problem.
In a sample application, I have 2 routes and I am in Page1.
Once I click anywhere in Page1 component and go to Page2 via routerLink, I can see Page1 component as a detached element in memory snapshot.
This is a screenshot.
Image
I am in test-2 page now but can see app-test1 component is detached.

I tried in different Angular versions (12, 16, 19) and the behavior was exactly same.
Of course, I don't have any observables, pipes, services, ... My components are clean and it doesnt have any extra codes in component.ts files.
And I used only a and div tags in html.
It doesnt have any parent-child relationship too.

Can you please help me how I can fix this? or is this expected behavior in web applications?

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


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

Angular: 19.0.0
Node: 18.19.1
NVM
OS: Windows 10
Package.json
{
  "name": "new-test-detached",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^19.0.0",
    "@angular/common": "^19.0.0",
    "@angular/compiler": "^19.0.0",
    "@angular/core": "^19.0.0",
    "@angular/forms": "^19.0.0",
    "@angular/platform-browser": "^19.0.0",
    "@angular/platform-browser-dynamic": "^19.0.0",
    "@angular/router": "^19.0.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.15.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^19.0.1",
    "@angular/cli": "^19.0.1",
    "@angular/compiler-cli": "^19.0.0",
    "@types/jasmine": "~5.1.0",
    "jasmine-core": "~5.4.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "typescript": "~5.6.2"
  }
}

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: devtoolsmemory leakIssue related to a memory leakneeds reproductionThis issue needs a reproduction in order for the team to investigate further

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions