Open
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
v8.x
Current Behavior
Navigating between pages in an Ionic + Angular application leads to a steadily increasing DOM node count. Over time, this can balloon to tens of thousands of detached DOM nodes (verified via Chrome DevTools), causing performance degradation and application crashes.
Expected Behavior
When a component or page is destroyed/navigated away from, its DOM elements should be properly removed from memory. The DOM node count should not grow indefinitely, ensuring stable performance over time.
Steps to Reproduce
- Clone code reproduction URL +
npm install
+npm start
- Open Chrome DevTools → Performance & Memory tab.
- Repeatedly navigate next, then back to root. Each will load 5000 nodes.
- Note, ngOnDestroy successfully executes
- Observe the DOM node count growing with each navigation in the Performance Monitor, and detached DOM nodes in the Memory tab snapshots. Forcing Garbage collection has no effect.
- Snapshotting at root, and then again at root after navigation shows
Detached <div>
of the exact count with setObjects allocated between Snapshot X and Snapshot X
Screen.Recording.2025-02-26.at.9.40.18.am.mov
Code Reproduction URL
https://github.com/ralphcode/capacitor-angular-dom-leak
Ionic Info
Ionic:
Ionic CLI : 7.2.0
Ionic Framework : @ionic/angular 8.5.0
@angular-devkit/build-angular : 18.2.14
@angular-devkit/schematics : 18.2.14
@angular/cli : 18.2.14
@ionic/angular-toolkit : 12.1.1
Utility:
cordova-res : not installed globally
native-run (update available: 2.0.1) : 1.4.0
System:
NodeJS : v18.20.3
npm : 10.7.0
OS : macOS Unknown
Additional Information
Possibly related to: #30132 (specifically Resolved performance issues due to detached nodes in memory
) and here within Stencil/Core: stenciljs/core#6210
If you need anything further, please let me know