Backbone.js Memory Management, Rising DOM Node Count

前端 未结 4 1318
忘了有多久
忘了有多久 2020-12-14 09:59

Situation: I\'m working on a pretty decently complex single page Backbone app that could potentially be running for 8-12+ hours straight. Because of this, t

4条回答
  •  情话喂你
    2020-12-14 10:50

    It's fixed! - UPGRADE BACKBONE. (continue reading)

    We upgraded from Backbone 0.9.2 to Backbone 0.9.10 and implemented the listenTo and stopListening on every view/model/collection. The results are OMGFANTASTIC.

    After 7 minutes of running the same stress-test, these are the results: enter image description here

    Results: 7.0 minutes, 6,926 DOM Nodes (Without the timeline recording) and the Event Listener Count looks like BLUE BLADES OF GRASS. I'm shocked. The memory usage is also amazingly low in comparison to previous tests.

    After 18 Minutes: The event listener count is the same, never surpassing 154 and the DOM Node Count stays below 25,000 the entire time! There are obviously some things slipping by (some non-backbone components that are still in use, most-likely) but the improvement is astounding.

    Conclusion: Prior to this version of Backbone, we were not doing a very good job cleaning up listeners within Backbone itself. The listeners to the DOM were handled fine, but not between models/views/collections. Many of the callbacks involved were tied to Backbone Views which I guess prevented the garbage collector from freeing up the DOM Nodes. Lots of straggling event listeners/callbacks within Backbone (not just binding to the DOM) create a lot of straggling DOM Nodes that can't be garbage collected.

    If this isn't a good enough reason to upgrade Backbone, I don't know what is ;o

提交回复
热议问题