gpt4 book ai didi

javascript - JS引擎什么时候创建Garbage Collection Root?

转载 作者:数据小太阳 更新时间:2023-10-29 06:12:57 27 4
gpt4 key购买 nike

一点背景

我正在使用 ExtJS3 开发大型 JS 应用程序。在运行时,用户可能会打开和关闭许多小部件,因此可能会增加内存使用量。我使用 Chrome's heap analyzer 修复了许多内存漏洞,但在某些情况下,我就是找不到罪魁祸首。堆分析器显示类似 GCRoot[1234]->store.items 的内容,但我找不到引用存储的代码部分。

问题

V8(或任何其他 JS 引擎)创建新垃圾收集器根的确切运行时条件是什么?是否有特定的代码模式(闭包、评估、事件列表等)强制执行?

最佳答案

GC roots are the special group of objects that are used by the garbage collector as a starting point to determine which objects areeligible for garbage collection. A “root” is simply an object that thegarbage collector assumes is reachable by default, which then has itsreferences traced in order to find all other current objects that arereachable. Any object that is not reachable through any referencechain of any of the root objects is considered unreachable and willeventually be destroyed by the garbage collector. In V8, roots consistof objects in the current call stack (i.e. local variables andparameters of the currently executing function), active V8 handlescopes, global handles, and objects in the compilation cache.

通过http://zetafleet.com/blog/google-chromes-heap-profiler-and-memory-timeline

Q: What comprises GC roots?

A: Many things:

  • built-in object maps;
  • symbol table;
  • stacks of VM threads;
  • compilation cache;
  • handle scopes;
  • global handles.

通过http://code.google.com/chrome/devtools/docs/heap-profiling.html

关于javascript - JS引擎什么时候创建Garbage Collection Root?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9748358/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com