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

标签 javascript v8

一点背景

我正在使用 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/

相关文章:

javascript - 为什么 "requestAnimationFrame"递归不会耗尽 RAM?

google-apps-script - 如何从 Rhino 为 V8 重写此代码?

javascript - 独立的 javascript 应用程序,html5 Canvas 游戏...最好使用 V8,或基于浏览器调整游戏

javascript - 移动设备上的语义 UI 滚动下拉菜单

javascript - 在使其可见之前告知 Google map 圆圈对象何时移动

parsing - 我如何访问 v8 解析树怎么做?

javascript - 'sort'方法在chrome环境和node环境有什么区别

javascript - BaseX:Javascript 函数在 XSLT 中不起作用

javascript - 如何使用 php、AJAX 或 MySQL 使删除按钮完全发挥作用并具有正确的 ID?

javascript - 如何在 <audio> 标签中检测 mp3 中的音频 channel 数?