bitsbuffer
bitsbuffer

Reputation: 555

memory leak issue in Backbonejs App

I'm using Backbonejs and Requirejs for creating a single page web app. It seems like my app has memory leaks.

For testing I've created a sample code. It creates a view object, call its render function and attach the returned html into the DOM.
The returned html has a button. After clicking the button, its callback calls destroy function where the view is destroyed.

However, when I run chrome heap profilier, I can see detached DOM tree still hanging around. Looking deep into it, one can see references kept by jQuery.

I have doubt whether this is memory leakage or not. If yes mycode is not keeping any references. So does the problem lies in jQuery ?

Here's is link to sample code.
I've also attached screen shots of heap snapshots.

Heap snapshot 1

Heap snapshot 2

References for Detached DOM element

Upvotes: 9

Views: 1582

Answers (2)

user1649981
user1649981

Reputation: 11

go through this links u will get more idea and you may find possible solution to your problem

https://paydirtapp.com/blog/backbone-in-practice-memory-management-and-event-bindings/

http://lostechies.com/derickbailey/2012/03/19/backbone-js-and-javascript-garbage-collection/

best of luck I hope you solve this problem quickly

Upvotes: 1

Software Engineer
Software Engineer

Reputation: 16110

Applications built using backbone often have memory leaks caused by orphaned views. I deal with this by using marionette which manages my views for me. Using backbone directly isn't a typical approach, as it's really a toolkit upon which frameworks are developed.

Upvotes: 1

Related Questions