每次重新加载页面时,我的网络应用程序(使用lit-element构建)变得越来越慢。开始寻找泄漏,这似乎是由我通过类字段初始化的元素引起的:
export class SearchAutocomplete extends LitElement {
searchInput: TextInput = new TextInput();
...
}
删除该行后,GC会正常运行。
但是,这使我想知道为什么以上行阻止 tree 成为垃圾回收?
此外,为什么在重新加载页面后内存仍然绑定到窗口,难道不应该立即清除内存吗?
当我们重新加载/硬重新加载页面时,实际上发生了什么,那突显等于location.reload()
吗?
谢谢!