Repository navigation
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.
Stencil Version
4.25.0
Current Behavior
Components created by the output target dist still have the a memory leak.
The latest fix of that issue indeed fixed half of the problems. If we take a look closer we'll see that:
- introduced a new function that removes items from the WeakMap here
- this function will be called in the
disconnectedCallbackhere
And that works perfectly for the type dist-custom-elements. In the second point, we can see that this function is called.
But for the type dist this function wasn't called here
To reproduce that I've created an empty project here. That project has two types of output: dist and dist-custom-elements.
If we run the build command and compare the output results we'll next thing: the function deleteHostRef will be called only in the specific dist-custom-elements output type.


I've also tried to modify the output of the dist by adding the hostRefs cleaning, but it didn't change the result. I guess I'm missing something here:

Demo
I recorded a small demo to check that. The app renders 121 components, so I removed all those components with the console and then checked the memory.
In the first part, I perform a memory test for the dist output target. We see that the components are still stored in memory.
In the second part I connect files generated by the dist-custom-elements and do the same but there are no components.
Expected Behavior
I guess if we add the deleteHostRef for the disconnectedCallback here it might fix the issue.
System Info
Steps to Reproduce
- Clone the repo: https://github.com/seregindev/stencil-memory-test
- run
npm i && npm run build - Compare the outputs
- Connect components generated by the
dist - Delete components and measure memory
- Components are still kept
- Connect components generated by the
dist - Delete components and measure memory
- Components are removed
Code Reproduction URL
Additional Information
No response
Activity
christian-bromann commentedon Feb 4, 2025
This has been released in
@stencil/[email protected]seregindev commentedon Feb 5, 2025
Many thanks @christian-bromann! I just tested and there is no more memory leak! Great job 💪
MosheSchnitzler commentedon May 6, 2025
When is this update set to be bundled with the ionic package on NPM?