-
Notifications
You must be signed in to change notification settings - Fork 791
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: conditional rendering with ionic component causes memory leak #5172
Comments
Hey 👋 Thanks for the issue! I’ve taken an initial look at the reproduction case you’ve provided, and it does appear there is a memory leak of some type occurring here. Before we move forward with this, can you help us out with a few things? Can you do me a favor and split this issue into two, one for each type of leaking described? The reason I ask is:
Splitting the issue can be done by creating a new issue, copying the existing details from the second reported leak into the new issue. From there, someone on the team will take a closer look at each issue and may follow up/request some additional information. Thanks! |
Thank you so much! I split the second kind of leak into another one, #5181 . Since the second one affects production, it should be considered more important. However, this one occurs in the development environment, making it challenging to identify issues in production. Therefore, both are very important. I hope to hear from the team soon! |
Thanks @lucas-quinn ! I took the liberty of moving the list of Ionic Components to a collapsible section in the issue summary to minimize some additional scrolling, as well as adding another reference to the second issue there. Can you do me a favor and for this issue, add a few screenshots of what you're seeing in terms of memory leaks? While I think we're on the same page, I'd like to make sure we're working on the issue/type of memory leak reported here. Thanks! |
@rwaskiewicz Thanks! I have added two screenshots. I'm using Microsoft Edge - Detached Elements here because Chrome doesn't offer this devtool to easily debug detached elements. But Chrome does offer memory profiling. |
Thanks @lucas-quinn! I've validated this bug with the reproduction case + the screenshots. I've labeled it to get it ingested into our backlog to prioritize. |
I'm not 100% sure, but I think we may be running into this leak as well. Mostly it is just some ZoneAwarePromise objects that are retained, but sometimes we have HTMLElements as well. The retainers always point to the constructor in Line 101 of bootstrap-lazy.ts: We're running: |
Prerequisites
Stencil Version
@stencil/core at all versions, 2.x, 3.x, 4.x and the latest 4.8.2. Haven't tried 1.x.
Current Behavior
I have identified two types of memory leaks so far. The first type occurs in the development environment and is caused by components like
ion-button
.The second type is more complex, but more importantly, it happens in prod build too - this has been moved to #5181
Let's focus on the memory leak in the development environment in this issue.
The First Kind of Leaking
When rendering a component conditionally, certain components, such as
ion-button
, trigger a memory leak. If the component exists in a Stencil component and is rendered conditionally, the entire Stencil component fails to be garbage collected. For instance, wrappingion-button
in a Stencil component and rendering it conditionally prevents the garbage collection of the Stencil component.While this type of leaking is limited to the development environment, distinguishing between development-only and production-related leaks is challenging. This ambiguity significantly impacts the development experience, requiring extensive time spent on debugging memory leaks. To determine whether a component is leaking, one must build and run the app in production mode, adding a considerable overhead to the debugging process.
Environment details:
Ionic@latest
React@latest: Perfectly clean
Angular@latest: Perfectly clean
Vue@latest: One element left in memory, but it cleans memory correctly
Stencil@latest: Unable to perform garbage collection correctly, resulting in memory leaks
To reproduce the issue:
npm install
.npm run start
.Replace
ion-button
with other components to observe the same issue:Expand to see components
The Second Kind of Leaking
Moved to #5181
Expected Behavior
Detached elements should be garbage collected.
System Info
npx @stencil/core info
Tried different browsers, different systems, different node versions, different typescript versions too.
Steps to Reproduce
Clone the repo
To reproduce the issue:
npm install
.npm run start
.https://github.com/lucas-quinn/ionic-memory-leak
Additional Information
No response
The text was updated successfully, but these errors were encountered: