Skip to content
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

stop holding a reference to a Promise when it is resolved #1284

Merged
merged 1 commit into from
Apr 3, 2023

Conversation

ceymard
Copy link
Contributor

@ceymard ceymard commented Apr 3, 2023

I'm coming back on this closed PR : https://astegmaier.github.io/cached-promise-memory-leak/index.html

I still observe memory leaks in my application due to the includeFile Map. It would seem there is some regression around Promises in Chrome at least.

Wouldn't it still be somewhat better to guard against this possibility by not holding the promise objects in the Map to be sure ?

This approach is a lot simpler (I forgot that Promise.resolve() actually unboxes Promises), maybe you would consider it mergeable ?

@vercel
Copy link

vercel bot commented Apr 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
shoelace ✅ Ready (Inspect) Visit Preview Apr 3, 2023 0:22am

@claviska
Copy link
Member

claviska commented Apr 3, 2023

This looks much simpler! Thanks for updating it. Do you think it's worth adding a comment to explain why we're doing it this way? Feel free to paste a link back to this PR for context.

@ceymard
Copy link
Contributor Author

ceymard commented Apr 3, 2023

Yes I was actually thinking about explaining it but since there were no comments I restrained myself. I'll comment it.

@ceymard
Copy link
Contributor Author

ceymard commented Apr 3, 2023

For reference, this PR addresses unresolved points we had in #1249 relative to the handling of Promises in the includeFiles Map used to cache network results, especially for icons.

In some browser implementations, the Promise objects seem to cause a leak by retaining all the code that used then() on them. It's weird, it shouldn't happen (one would assume that when it is resolved, all the pending then() calls are completely flushed), but it definitely does.

The "fix" is to remove the Promise objects from the Map once they've resolved to make sure they don't retain anyone.

@ceymard
Copy link
Contributor Author

ceymard commented Apr 3, 2023

Force pushed with the comments.

Copy link
Member

@claviska claviska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@claviska claviska merged commit 91ffaa1 into shoelace-style:next Apr 3, 2023
yuki24 pushed a commit to yuki24/shoelace that referenced this pull request May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants