Backbone 嵌套的 View 在 父级 的 View 被清除时能否自动垃圾回收?

Github 看到讨论这个, 作者的回复里提到这一句了:

https://github.com/documentcloud/backbone/issues/2490#issuecomment-16514082

In a more agnostic setup, if the HTML for your subviews is removed at the same time that the models stop being referenced, it all just gets garbage collected for you. The more unnecessary references you have in JS, the less garbage collection gets to do its job. We should try to have as few as possible mandated by core Backbone.

这个过程具体是怎么回事的?

关于 JS 垃圾回收, 网上的说法是的没有引用时 JS 会进行回收, 在 Backbone 里怎么体现呢?

阅读 4.4k
1 个回答

谢邀!
趁着今天项目不忙,偷懒一会,大致看了下backbone,由于backbone毫无实际项目经验,我就说下我的大致理解吧,仅供参考,同时欢迎一起讨论,在backbone看来里,只要删除对视图实例的任何引用就足以标记它有资格进行回收。

主要参考文档:github issues

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题