title: Angular ShadowDom ViewEncapsulation memory leak
body: <p>I have been trying to identify memory leak in <code>electron Angular</code> app. I have searched through the Internet and found out that chromium had a bug on that topic in previous versions.</p>
  <p><a href="https://bugs.chromium.org/p/chromium/issues/detail?id=1308845" rel="nofollow noreferrer">Chromium bug</a></p>
  <p><a href="https://github.com/angular/angular/issues/45080" rel="nofollow noreferrer">Angular issue</a></p>
  <p>From that, I thought that the problem is in Chromium version. However, I have tried with the newest elecrton that has <code>Chromium 104.0.5112.65</code> where this should already have been fixed. However when analyzing memory leak in the dev tools using <strong>allocation timeline</strong> there are several <strong>Detached HTMLDivElements</strong> inside that cause memory to grow when components gets rerendered (reinitialized).</p>
  <p><a href="https://i.stack.imgur.com/s1oRn.png" rel="nofollow noreferrer">Detached HTMLDivElements</a></p>
  <p>Component containing ShadowDom:</p>
  <pre><code>@AutoUnsubscribe()
  @Component({
      selector: 'content',
      templateUrl: './content.html',
      styleUrls: ['./content.scss'],
      encapsulation: ViewEncapsulation.ShadowDom
  })
  export class ContentComponent implements OnInit, OnDestroy {
  
  
      @Input() innerHTML: any;
      @ViewChild('emailBody', { static: true }) private emailBody;
  
      constructor(
          private _renderer2: Renderer2
      ) {
      }
  
      ngOnInit() {
      }
  
      ngOnDestroy() {
      }
  }
  </code></pre>
  <p>This component is then used in HTML file to show HTML from BE where we set innerHtml. On item click in the sidebar the content component is initialized and the memory grows on every click on the sidebar...</p>
  <pre><code>&lt;content
      [innerHTML]=&quot;html&quot;&gt;
  &lt;/content&gt;
  </code></pre>
  <p>I have tried setting ViewEncapsulation to EMULATED but this then propagate HTML styles to the global html elements which is not what I want... However, setting this to emulated fixed the memory leak...</p>
  <p>Do you guys have any idea what should be done?</p>