一点背景
我正在使用 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 are eligible for garbage collection. A “root” is simply an object that the garbage collector assumes is reachable by default, which then has its references traced in order to find all other current objects that are reachable. Any object that is not reachable through any reference chain of any of the root objects is considered unreachable and will eventually be destroyed by the garbage collector. In V8, roots consist of objects in the current call stack (i.e. local variables and parameters of the currently executing function), active V8 handle scopes, 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/