我在我的主干代码中定义了一个 ListView 和 InstanceView。ListView 与一个集合相关联,它像这样实例化一个 InstanceView
render: function () {
this.collection.forEach(function(instance){
var commentHTML = new InstanceView({
model: instance
}).render();
renderedComments.push(commentHTML);
});
}
渲染调用完成后,新视图实例超出范围。不过,我注意到该视图仍然存在于内存中。我可以说是因为附加到它的事件在渲染方法终止后很长时间仍然会触发。
那么,视图是否因为它对模型对象的引用而避免 gc,而模型对象又被集合引用?