0

I have got 6-7 pages application which is using backbone views, jQuery and high charts. I have noticed that it is leaking memory. It become unresponsive if I leave it running for 10 minutes. Someone suggested me to destroy views when not in use and I did this according to this answer.

Destroy or remove a view in Backbone.js

Which improved app but still I have got memory issues. I'll appreciate if someone could guide me in correct direction. Is there anything else I can do to improve memory leaks?

Community
  • 1
  • 1
RuntimeException
  • 1,135
  • 2
  • 11
  • 25

2 Answers2

2

Most of memory leaks happen because of ghost events.

I suggest using listenTo when binding to events inside views. Calling view.remove() will automatically unbind them.

Andrey Kuzmin
  • 4,479
  • 2
  • 23
  • 28
  • +1, also you should avoid adding element to the DOM in the loop. Do it once. Also if you use a `comparator` avoid adding `models` to the `collection` in the loop too. – Vitalii Petrychuk May 14 '13 at 18:50
1

First of all you need to detect the root cause and only then fix it.

Tools for debugging memory leaks in JavaScript

Also I suggest to watch this screencast http://www.youtube.com/watch?v=L3ugr9BJqIs

Community
  • 1
  • 1
Vitalii Petrychuk
  • 14,035
  • 8
  • 51
  • 55