title: What is the correct way to destroy an element created with Renderer2?
body: <p>In our code base we have a virtual repeat directive that uses Renderer2 to create a div like this:</p>
  
  <pre><code>this.renderer2.createElement('div');
  </code></pre>
  
  <p>In the ngOnDestroy method we are destroying it like this:</p>
  
  <pre><code>this.renderer.destroyNode(this.offsetBeforeEl);
  </code></pre>
  
  <p>This worked fine and we had no issues until we built the application in prod mode and we started getting the following error:</p>
  
  <pre><code>main.js?d73b003…:formatted:87193 Uncaught (in promise) TypeError: this.renderer.destroyNode is not a function
  </code></pre>
  
  <p>I added a breakpoint to the that line and found that in fact destroyNode is not a method on Renderer2.  I went to the source code for angular and found the comment above the method in the abstract class defintion:</p>
  
  <pre><code>/**
     * This property is allowed to be null / undefined,
     * in which case the view engine won't call it.
     * This is used as a performance optimization for production mode.
     */
    destroyNode: ((node: any) =&gt; void)|null; 
  </code></pre>
  
  <p>So I checked out the code for the view and saw this:</p>
  
  <pre><code>if (view.renderer.destroyNode) {
    destroyViewNodes(view);
  }
  if (isComponentView(view)) {
    view.renderer.destroy();
  }
  </code></pre>
  
  <p>If I can't rely on this method existing, what is the correct way to destroy a node that was dynamically created using Renderer2?</p>