<p dir="auto"><strong>I'm submitting a ...</strong> (check one with "x")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[x] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question"><pre class="notranslate"><code class="notranslate">[x] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
</code></pre></div>
<p dir="auto"><strong>Current behavior</strong></p>

<p dir="auto">When navigating between components they don't get destroyed properly. A reference of the navigated component and its children is still in memory.</p>
<p dir="auto"><strong>Expected behavior</strong></p>

<p dir="auto">The components shouldn't be in memory after they where destroyed.</p>
<p dir="auto"><strong>Minimal reproduction of the problem with instructions</strong></p>

<p dir="auto"><a href="http://plnkr.co/edit/KF49IB82ffvRFXVdYtyx" rel="nofollow">?p=preview http://plnkr.co/edit/KF49IB82ffvRFXVdYtyx?p=preview</a></p>
<ol dir="auto">
<li>Open plunker</li>
<li>Click "Launch the preview in a separate window"</li>
<li>Click "Page2" button</li>
<li>Open Devtools</li>
<li>Go to Memory Tab</li>
<li>Take Heap Snapshot</li>
<li>Search for My</li>
</ol>
<p dir="auto">--&gt; Now you can see that there are still references to MyPage1, MyPage2 and two MyChild.</p>
<p dir="auto"><strong>Please tell us about your environment:</strong></p>

<ul dir="auto">
<li><strong>Angular version:</strong> 4.1.3</li>
</ul>

<ul dir="auto">
<li><strong>Browser:</strong> all</li>
</ul>

<ul dir="auto">
<li><strong>Language:</strong> TypeScript 2.2.1</li>
</ul>
<p dir="auto"><strong>I'm submitting a ...</strong>  (check one with "x")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[X] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question"><pre class="notranslate"><code class="notranslate">[X] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
</code></pre></div>
<p dir="auto"><strong>Current behavior</strong></p>

<p dir="auto">When triggering ComponentRef.destroy(), no browser memory is ever released. Any injected dependencies are all still there and running, even though the component is gone.</p>
<p dir="auto">Also:<br>
When bootstrapping an app within an iframe, destroying that app and removing the iframe from the DOM does not release browser memory.</p>
<p dir="auto">In both of these scenarios, browser memory builds up over time and the browser tab and angular app lock up or crash. Injected dependencies are created, but never removed.</p>
<p dir="auto"><strong>Expected behavior</strong></p>

<p dir="auto">Browser memory should be released as apps and components are destroyed.</p>
<p dir="auto"><strong>Minimal reproduction of the problem with instructions</strong></p>

<p dir="auto"><em>STEPS TO REPRODUCE</em></p>
<p dir="auto">REPRODUCING DEPENDENCY LEAK</p>
<ol dir="auto">
<li>
<p dir="auto">Run the Tour of Heroes plnkr in Chrome or IE<br>
<a href="https://plnkr.co/edit/R9axXVtjep5VO8hWygpA?p=preview" rel="nofollow">https://plnkr.co/edit/R9axXVtjep5VO8hWygpA?p=preview</a></p>
</li>
<li>
<p dir="auto">Open the js console and watch the logging in the hero service, which does not stop after destroying the app.</p>
</li>
</ol>
<ul dir="auto">
<li>Note, this is the Tour of Heroes example, except that after the app is bootstrapped in main.ts, I've added a 15sec timer that runs ref.destroy(). Additionally, in the hero.service.ts file, I added a console log in the constructor that prints every second. You can see that the service continues to run even after triggering .destroy() on the component ref.</li>
</ul>
<p dir="auto">REPRODUCING IFRAME LEAK</p>
<ol dir="auto">
<li>
<p dir="auto">Run the Tour of Heroes live example in IE 11<br>
<a href="https://angular.io/resources/live-examples/toh-6/ts/eplnkr.html" rel="nofollow">https://angular.io/resources/live-examples/toh-6/ts/eplnkr.html</a></p>
</li>
<li>
<p dir="auto">Open F12 dev tools, click on Memory and click "Start profiling to begin a performance session"</p>
</li>
<li>
<p dir="auto">Make changes to the files by adding line breaks. Every time the app reloads in the iframe the memory will grow. After about 15 minutes of this the app will lock up due to the IE tab hitting the 1.5Gb memory limit. If you test with app that has more dependencies, it will lock up much faster.</p>
</li>
</ol>
<p dir="auto">This can be reproduced in Chrome too, it just takes longer for the memory leak to build up that much.</p>
<p dir="auto"><strong>What is the motivation / use case for changing the behavior?</strong></p>

<p dir="auto">Large-scale angular apps that use iframes or rely on destroying components will leak memory over time and eventually crash or lock up.</p>
<p dir="auto"><strong>Please tell us about your environment:</strong></p>

<p dir="auto">Mac OS 10.11.6</p>
<ul dir="auto">
<li><strong>Angular version:</strong> 2.0.X</li>
</ul>

<p dir="auto">Angular v2.4.1</p>
<ul dir="auto">
<li><strong>Browser:</strong> [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]</li>
</ul>

<p dir="auto">all</p>
<ul dir="auto">
<li><strong>Language:</strong> [all | TypeScript X.X | ES6/7 | ES5]<br>
all</li>
<li><strong>Node (for AoT issues):</strong> <code class="notranslate">node --version</code> =</li>
</ul>