使用requre js和js匿名函数的javascript内存泄漏

时间:2015-05-15 11:58:39

标签: javascript memory-management require

执行下面的代码行后,GC没有收集User个对象。它正在镀铬堆快照上显示。

有人可以帮忙吗?

 define("mockModule", [], function () {
 function User(name) {
    var that = this;
    this.name = name;
    this.column = [{ id: 'xyz' }];
    this.createObj();
}
User.prototype.createObj = function () {
    var that = this;
    this.column[0]['formatter'] = outerFunction(that);
};
 User.prototype.dummyMethod = function () {
 } ;
 function outerFunction(that) {
    return function () {
        return that.dummyMethod(that)
    };
  }
 return { User: User };
});

    define("mockModuleImpl", ["mockModule"], function (mockModule) {
 function init() {
    var user = new mockModule.User("hello");
    user = null;
 }
 return { init: init }; 
});

  require(["mockModuleImpl"], function (mockModuleImpl) {
      mockModuleImpl.init();
});

0 个答案:

没有答案