Backbone Memory Leaks
Considering the uses of many Backbone views in single page apps, it is critically important to manage memory leaking. I found good articles and discussion around this topic.
Takeaways regarding Backbone Apps:
- Use ListenTo() when binding events.
- Use remove() to unhold references to a removed view, which will do two things: 1) remove the view and its 'el' from DOM, 2) unbind all events referenced/bound to the view with sending stopListening().
- Track subviews in a parent view: when the parent view is removed, remove its subviews too.
- console.log(zombie view) cannot be garbage-collected.
- Global objects and its attributes cannot be garbage-collected, until the page is refreshed.
Zombies! RUN!, by Derick Bailey
Managing Events As Relationships, Not Just References, by Derick Bailey
Backbone.js And JavaScript Garbage Collection, by Derick Bailey
Johnny Oshika's solution
How To: Detect Backbone Memory Leaks, by Andrew Henderson