接口: 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 元素