相关疑难解决方法(0)

使用Chrome查找JavaScript内存泄漏

我创建了一个非常简单的测试用例,它创建了一个Backbone视图,将一个处理程序附加到一个事件,并实例化一个用户定义的类.我相信通过单击此示例中的"删除"按钮,一切都将被清除,并且不应有内存泄漏.

代码的jsfiddle在这里:http://jsfiddle.net/4QhR2/

// scope everything to a function
function main() {

    function MyWrapper() {
        this.element = null;
    }
    MyWrapper.prototype.set = function(elem) {
        this.element = elem;
    }
    MyWrapper.prototype.get = function() {
        return this.element;
    }

    var MyView = Backbone.View.extend({
        tagName : "div",
        id : "view",
        events : {
            "click #button" : "onButton",
        },    
        initialize : function(options) {        
            // done for demo purposes only, should be using templates
            this.html_text = "<input type='text' id='textbox' /><button id='button'>Remove</button>";        
            this.listenTo(this,"all",function(){console.log("Event: "+arguments[0]);});
        },
        render : …
Run Code Online (Sandbox Code Playgroud)

javascript memory-leaks google-chrome backbone.js

158
推荐指数
4
解决办法
6万
查看次数