Interface: IHeapNodes
A pseudo array containing all heap graph nodes (JS objects in heap). A JS heap could contain millions of objects, so memlab uses a pseudo array as the collection of all the heap nodes. The pseudo array provides API to query and traverse all heap objects.
readonly modifying this pseudo array is not recommended
- Examples:
import type {IHeapSnapshot, IHeapNodes} 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 nodes: IHeapNodes = heap.nodes;
nodes.length;
nodes.get(0);
nodes.forEach((node, i) => {
if (stopIteration) {
return false;
}
});
})();
Properties
length: number
The total number of nodes in heap graph (or JS objects in heap snapshot).
- Source:
Methods
forEach(callback)
Iterates over all array elements and applies the callback to each element in ascending order of element index.
- Parameters:
callback: (node:IHeapNode,index:number) =>boolean|void| the callback does not need to return any value, if the callback returnsfalsewhen iterating on element at indexi, then all elements afteriwon't be iterated.
- Returns:
void - Source:
get(index)
Gets an IHeapNode element at the specified index.
Parameters:
index:number| the index of an element in the pseudo array, the index ranges from 0 to array length - 1. Notice that this is not the heap node id.
Returns:
Nullable<IHeapNode> | When 0 <=index< array.length, this API returns the element at the specified index, otherwise it returnsnull.Source: