Search code examples
memory-leaksgoogle-chrome-devtoolscustom-elementlit-elementlit-html

eventContext leaking with LitElement


I'm using lit-element (v2.3.1) & lit-html (v1.2.1) and having a memory leak where as a result of rendering, detached DOM nodes are not cleaned by GC and the only retainers shown for them by Chrome DevTools are WeakMaps used internally by lit-html to keep track of parts:

enter image description here

This doesn't happen with all renders, but I have not found a difference between the templates/renders that do and do not leak. Seems almost random. But maybe I'm missing something obvious here, would be glad to hear any suggestions regarding this.


Solution

  • As it happens, there is a known issue with one of the web components I'm using (mwc-ripple) where it attaches event listeners to window and fails to remove them, thus, the browser keeps in memory the whole tree containing the element leading to the memory leak described.