New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: Navigating between pages inside an Ionic app is leaking DOM nodes #19242
Comments
Confirmed this in my app. Memory references appear to be retained across page refreshes as well. It does appear if you leave the app idling for a while that GC occurs and references are cleaned up, but it does take a while for this to happen. |
I believe I have finally traced the memory leak down to the Here the observer is created: But there is no "componentDidDestroy" callback to clean up the listener, nor is there any code that would perform such cleanup elsewhere. I do not know if Stencil supports such a concept, but... without it, (as I understand it) this will never be cleaned up as the Observer will not clean itself up, and the observer contains a reference to the component/element being observed. I verified this by using the following image component:
When using 'native' images, DOM elements did not leak across page transitions where images were displayed. Garbage collection properly cleans up the Detached Dom elements and the pages can be destroyed. Using |
Thanks for investigating. Is this the same issue as the one OP posted about? The demo app provided does not seem to make use of |
@liamdebeasi Possibly not the same as the OP's issue. I just remembered this one was still here and seemed on topic. |
Great find @lincolnthree! My demo did not use any However, after using Ionic in a medium sized app for a while now I get the feeling that there are multiple Ionic components that are leaking (or maybe just a few leaks in some heavily used components like the It would be nice if the Ionic team tried to systematically identify and fix all of them at once rather than just try to fix the ones that get reported in various issues (not sure if that's possible though). |
Sorry to bring you this guys but this issue still persists and using |
Hi everyone,
See #19242 (comment) |
Hi everyone, I looked into this more and I can confirm that there is no memory leak in the reproduction provided. After upgrading the repo in #19242 (comment) to Angular 13 + Ionic 6, I was able to reproduce the reported behavior. However, the DOM nodes + event listeners do get garbage collected after a while. For example, this is the behavior I get after routing and going back several times: There are a couple of things to point out:
I am going to close this as this is not a bug in Ionic. Thank you! |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Bug Report
Ionic version:
[x] 4.8.1
Current behavior:
Navigating between pages leaks DOM nodes.
Expected behavior:
Navigating between pages should not leak DOM nodes.
Steps to reproduce:
The easiest way to reproduce it is by repeatedly navigating between two pages while monitoring the DOM nodes count.
Simple demo app which easily reproduces the problem: Ionic navigation DOM node leaks.
Steps to reproduce inside the demo app:
Performance monitor
openCollect garbage
button in Chrome devtools (found inside the Performance tab)Notice how each iteration of opening and closing the demo page increases the number of DOM nodes reported by the
Performance monitor
:The staircase pattern seems to suggest there's a memory leak that happens while navigating between pages in an Ionic app.
Related code:
Ionic navigation DOM node leaks demo
Other information:
The content of the page linked to seems to affect the number of DOM nodes leaked. For example, if the linked page contains
<ion-content>Hello world</ion-content>
then the number of leaked DOM nodes after each iteration is 7. However, if the page contains a div instead of an ion-content (e.g.:<div>Hello world</div>
) then the number of leaked DOM nodes decreases to 3.Ionic info:
The text was updated successfully, but these errors were encountered: