跳到主要内容

接口: IHeapEdges

一个伪数组,包含所有堆图边(堆中堆对象的引用)。一个 JS 堆可能包含数百万个引用,因此 memlab 使用一个伪数组作为所有堆边的集合。 该伪数组提供了 API 来查询和遍历所有堆引用。

readonly 不建议修改此伪数组

  • 示例:
import type {IHeapSnapshot, IHeapEdges} from '@memlab/core';
import {dumpNodeHeapSnapshot} from '@memlab/core';
import {getFullHeapFromFile} from '@memlab/heap-analysis';

(async function () {
const heapFile = dumpNodeHeapSnapshot();
const heap: IHeapSnapshot = await getFullHeapFromFile(heapFile);

const edges: IHeapEdges = heap.edges;
edges.length;
edges.get(0);
edges.forEach((edge, i) => {
if (stopIteration) {
return false;
}
});
})();

属性

length: number

堆图中的边总数(或堆快照中的 JS 引用)。

方法

forEach(callback)

迭代所有数组元素,并将回调应用于每个元素,元素索引按升序排列。

  • 参数:
    • callback: (edge: IHeapEdge, index: number) => boolean| void | 回调不需要返回任何值,如果在迭代索引为i的元素时回调返回false,则不会迭代i之后的所有元素。
  • 返回: void
  • 来源:

get(index)

获取指定索引处的 IHeapEdge 元素

  • 参数:

    • index: number | 伪数组中元素的索引,索引范围从 0 到数组长度 - 1。请注意,这不是堆节点 id。
  • 返回: Nullable<IHeapEdge>| 当 0 <= index < array.length 时,此 API 返回指定索引处的元素,否则返回 null

  • 来源: