【发布时间】:2017-06-17 13:22:01
【问题描述】:
我创建了一个对象this.bookView = new BookView();
当我执行this.bookView=null 时,垃圾收集器没有删除对象。
Google Dev Tool Profile Snapshot Retainers 窗口显示下面的连接(这表明某物引用了该对象)。
除context in () 外,所有行均为"Preview is not available"。
问题是BookView 有addSheet 函数变量,它还没有在任何地方使用过(还没有),但通过_this 拥有一个对自身的引用。
我尝试了什么:
1) this.bookView.addSheet = null;(没有帮助)
2) delete this.bookView.addSheet;(没有帮助)
我的问题:
1) 如何从 Window 中移除此连接并使bookView 被垃圾回收?
2) 为什么addSheet 变量是从Window 对象链接的?
3) retainers 窗口上的transitions 和descriptors 是什么?
4) 我可以使用哪些其他工具来查找有关这种内存泄漏的更多详细信息。
附: bookView 对象是在 Durandal 页面内创建的。 this.bookView 基本上是 page1.bookView。该页面已正确删除。在deactivate(页面删除)功能期间,我调用this.bookView = null;
【问题讨论】:
-
addSheet或AddSheet? -
错字,已修复。
addSheet。谢谢 -
如果您已暂停调试器并且某些相关变量显示在面板或控制台中,则 devtools 调试器本身可能会保留引用。
-
尝试使用
this而不是_this。无论如何,您应该发布您的代码。见minimal reproducible example
标签: javascript typescript google-chrome-devtools