-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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: chrome, complex selector causing elements to not get garbage collected #26833
Comments
Thanks for the report. I can reproduce this behavior, but I am still digging into the source of the issue. I'll update here when I have more information. |
Thanks @liamdebeasi. I've spent a lot of hours looking at this for the last week or so, if you'd like to chat about it in person let me know. |
This appears to be a Chromium bug. All overlays receive an ionic-framework/core/src/css/core.scss Line 95 in 6dcd98b
This complex selector seems to be causing the issue. Removing it causes the issue to no longer reproduce. I was able to reproduce this behavior outside of Ionic, and I have reported this issue to the Chromium team: https://bugs.chromium.org/p/chromium/issues/detail?id=1418768 I will see if there is an alternative implementation for the selector above. |
Hi @liamdebeasi If I go the reproduction URL (https://ionicframework.com/docs/usage/v6/modal/controller/demo.html?ionic:mode=ios) and remove the Ionic CSS element from the page, and then run the same steps, exactly the same behaviour still happens for me? I'm also not convinced this can just be a Chromium bug as I can reproduce this easily in Safari as well? |
It's possible there are multiple memory leaks. Can you provide Safari reproduction steps? Also, you'll want to remove the |
Yea I suspect there are multiple memory leaks, which is why I'm a bit concerned you've renamed and labeled this as a Chromium bug only - I don't want the other issues getting forgotten about. At the least I think the underlying Stencil issues I mentioned in my original post are contributing somehow. Also I wonder if the modal holding strong references to e.g. The steps are the same in Safari, just you need to use the timeline to monitor the leak. (I run |
If there are additional memory leaks in Stencil, then those issues should be tracked in ionic-team/stencil#4070 and ionic-team/stencil#4067 instead. I'll look into the Safari reproduction. |
Yes apologies I meant to write |
I see a few more retainers:
This issue only appears to impact the lazy loaded bundle of Stencil, so There are a couple areas in Ionic where we are holding onto references. These do not appear to be contributing to the problem, but we should still fix them:
I'll keep this ticket open until #26856 and #26855 are merged. Also it looks like the Chromium team has verified the bug I reported the other day: https://bugs.chromium.org/p/chromium/issues/detail?id=1418768 |
Hi @liamdebeasi Nice work on finding the extra retainers. I'm not sure I agree that the 2 stencil issues I've raised cover any of your first 3 bullet points. When you say this only impacts the lazy loaded bundle of Stencil, I tried doing this myself in a simple example repository and I still see the same behaviour. Link here: I also don't really agree that this issue should be closed once your 2 smaller fixes are merged. My original issue (before it was renamed) was that controller modals leak resources, and that will still be the case after your fixes are merged. If Stencil was a 3rd party library I could understand, but it's essentially a custom made build tool for Ionic, so whether the problems are with Ionic or Stencil to me as a user of the library doesn't really make a difference. My users are still experiencing the app crashing regularly. |
Sorry, my previous wording was not clear. Anything that causes Stencil components to be lazily loaded is impacted by this bug. In other words, if you are not explicitly importing and calling
I'll file some separate issues with the Stencil Team, but we typically do not keep 3rd party bugs open (the exception being browser-related bugs). We used to do it for older issues, but it makes tracking the state of the bug hard since you essentially have multiple sources of truth across multiple teams. |
My example repository literally does import each custom element and define it, as per the documentation (I think)
|
Do you have a link to your repository? All I saw in the previous comment was https://zippy-seahorse-69a6db.netlify.app/. |
Sorry, here's the code: |
Hmm that's odd, video of me running it here: |
Are you still able to reproduce the issue at https://ionicframework.com/docs/usage/v6/modal/controller/demo.html?ionic:mode=ios? The two references I noted in #26833 (comment) were cleaned up and shipped in Ionic 6.5.7 earlier this week. I'm not able to reproduce the issue anymore. (It appears these references were more significant than I originally noted) |
@liamdebeasi yea still seems to happen for me, if I go to that page and run the script above
and watch the performance tab, the nodes and listeners still increase indefinitely |
Is that with the |
Yea even if I remove the for the ionic css |
I was able to avoid the Chrome memory leak bug in: #26911 I'll take a look at any remaining retainers once that fix ships. |
A workaround for the Chrome memory leak bug shipped out today. I gave the repo another test using your code in #26833 (comment) and things seem better: Can you take another look? |
Hi @liamdebeasi yea just ran my test again locally and it seems to be sorted now! I see the same graphs as you and the number of nodes and listeners always returns back to the same number after a GC. Nice work! |
Great! Sounds like the issue is resolved, so I am going to close the thread. If you see the issue appear again feel free to reply, and I can re-open this. |
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. |
Prerequisites
Ionic Framework Version
Current Behavior
When a controller modal is dismissed, it's contents are detached from the DOM but are unable to me garbage collected. This represents a resource leak, and repeated opening/closing of a modal like this will eventually lead to the app being killed by the operating system.
Expected Behavior
When a modal is dismissed, all resources associated it should be freed.
Steps to Reproduce
https://ionicframework.com/docs/usage/v6/modal/controller/demo.html?ionic:mode=ios
A video of me doing these steps:
https://drive.google.com/file/d/1ciQxC1xSa_aiyrA2OfEIJCjXHJH_sBhx/view?usp=sharing
Code Reproduction URL
https://ionicframework.com/docs/usage/v6/modal/controller/demo.html?ionic:mode=ios
Ionic Info
Ionic:
Ionic CLI : 6.20.6 (/Users/joewoodhouse/.nvm/versions/node/v16.14.2/lib/node_modules/@ionic/cli)
Capacitor:
Capacitor CLI : 4.6.2
@capacitor/android : 4.6.3
@capacitor/core : 4.6.3
@capacitor/ios : 4.6.3
Utility:
cordova-res : not installed globally
native-run : 1.7.1
System:
NodeJS : v16.14.2 (/Users/joewoodhouse/.nvm/versions/node/v16.14.2/bin/node)
npm : 8.7.0
OS : macOS
Additional Information
I believe these issues are probably related to an underlying Stencil problem, but I haven't been able to track it down. As part of my investigation I've found other issues in stencil namely
ionic-team/stencil#4070
ionic-team/stencil#4067
There are known issues around how Stencils runtime and VDOM implementation hold strong (rather than weak) references to DOM nodes that are probably also contributing to this issue.
Whilst obviously for a documentation website this isn't a problem, for us this represents a major problem as we have a mobile application that displays 100s of modals during the course of the apps lifetime. This bug means that are users regularly experience crashes after a moderate amount of use, simply because the operating system kills the WebView due to it using too many resources. Using inline modals could be an option for us but it would require a major refactor.
The text was updated successfully, but these errors were encountered: