# How to deal with memory leak in EmberJs?

**URL:** <https://discuss.emberjs.com/t/how-to-deal-with-memory-leak-in-emberjs/5920>\
**Category:** Uncategorized\
**Created:** [July 17, 2014, 10:21am UTC](https://discuss.emberjs.com/t/how-to-deal-with-memory-leak-in-emberjs/5920 "2014-07-17T10:21:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hwoarangzk](https://avatars.discourse-cdn.com/v4/letter/h/919ad9/32.png) [@hwoarangzk](https://discuss.emberjs.com/u/hwoarangzk)\
**Post date:** [July 17, 2014, 10:21am UTC](https://discuss.emberjs.com/t/how-to-deal-with-memory-leak-in-emberjs/5920/1 "2014-07-17T10:21:36Z")

</div>

I opened my application, and switched between different pages, then I found that the reaction of the page became slow. For example, when I clicked a button, there was an obvious delay before the event got handled. Why did this happen? Is it because I binded event handlers in didInsertElement? When I jumped to another page, did the event handler got destroyed for the previous page? If not, how could I solve this issue? Thank you

---

<div class="post-metadata">

**Author:** ![muchweb](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/muchweb/32/13437_2.png) [@muchweb](https://discuss.emberjs.com/u/muchweb)\
**Post date:** [July 17, 2014, 11:34am UTC](https://discuss.emberjs.com/t/how-to-deal-with-memory-leak-in-emberjs/5920/2 "2014-07-17T11:34:53Z")

</div>

You can try [adding actions to controllers or routers](http://emberjs.com/guides/templates/actions/) instead.

---

<div class="post-metadata">

**Author:** ![ramchiranjeevi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ramchiranjeevi/32/15470_2.png) [@ramchiranjeevi](https://discuss.emberjs.com/u/ramchiranjeevi)\
**Post date:** [July 17, 2014, 12:42pm UTC](https://discuss.emberjs.com/t/how-to-deal-with-memory-leak-in-emberjs/5920/3 "2014-07-17T12:42:05Z")

</div>

@hwoarangzk When you bind an event in didInsertElement, you need to tear down the event in **willDestroyElement**.

Hence unbind your events in willDestroyElement function. So when you navigate to another route it will go into willDestroyElement and unbind all your events related to the route.

---

<div class="post-metadata">

**Author:** ![Jun\_Andrew\_Hu](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jun_andrew_hu/32/224_2.png) [@Jun\_Andrew\_Hu](https://discuss.emberjs.com/u/Jun_Andrew_Hu)\
**Post date:** [July 17, 2014, 6:51pm UTC](https://discuss.emberjs.com/t/how-to-deal-with-memory-leak-in-emberjs/5920/4 "2014-07-17T18:51:48Z")

</div>

Right.

But I think this might be something else, even if you bind a lot of events in didInsertElement, it should not drag down the perf much.

Have you used memory inspector to see if it is really memory causing the issue? If it is memory, it should cause a gc at some point and the perf should go back normal.

---

<div class="post-metadata">

**Author:** ![hwoarangzk](https://avatars.discourse-cdn.com/v4/letter/h/919ad9/32.png) [@hwoarangzk](https://discuss.emberjs.com/u/hwoarangzk)\
**Post date:** [July 18, 2014, 1:07am UTC](https://discuss.emberjs.com/t/how-to-deal-with-memory-leak-in-emberjs/5920/5 "2014-07-18T01:07:43Z")

</div>

I didn’t use memory inspector, any tool recommended? Firefox and Chrome are the only browsers supported in my app. Thanks

---

<div class="post-metadata">

**Author:** ![rogeruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rogeruiz/32/9838_2.png) [@rogeruiz](https://discuss.emberjs.com/u/rogeruiz)\
**Post date:** [July 18, 2014, 7:36am UTC](https://discuss.emberjs.com/t/how-to-deal-with-memory-leak-in-emberjs/5920/6 "2014-07-18T07:36:52Z")

</div>

These are two helpful guides on inspecting memory leaks in the Chrome Dev Tools.

> **[Chrome DevTools - Chrome Developers](https://developer.chrome.com/docs/devtools/)**
>
> Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser.

> **[Chrome DevTools - Chrome Developers](https://developer.chrome.com/docs/devtools/)**
>
> Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser.
