我一直在尝试在我的应用程序代码中跟踪垃圾收集的任何问题.我已将其剥离为纯粹的淘汰代码,并且根据计算属性的创建方式,似乎存在收集创建对象的问题.
请看以下JS小提琴:http: //jsfiddle.net/SGXJG/
请参阅以下代码以获取viewmodel:
function ViewModel() {
this.test1 = null;
this.test2 = null;
this.test3 = null;
}
ViewModel.prototype = {
makeAll: function () {
this.make1();
this.make2();
this.make3();
},
make1: function () {
this.test1 = new Test1();
this.test1.kill();
delete this.test1;
},
make2: function () {
this.test2 = new Test2();
this.test2.kill();
delete this.test2;
},
make3: function () {
this.test3 = new Test3();
this.test3.kill();
delete this.test3;
},
};
ko.applyBindings(new ViewModel());
Run Code Online (Sandbox Code Playgroud)
以下是三个测试类:
function Test1() { …Run Code Online (Sandbox Code Playgroud)