VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-v8-getheapspacestatistics-method/

⇱ Node.js v8.getHeapSpaceStatistics() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js v8.getHeapSpaceStatistics() Method

Last Updated : 5 Apr, 2023

The v8.getHeapSpaceStatistics() method is an inbuilt application programming interface of the v8 module which is used to get statistics about heap space derived from the v8 version.

Syntax:

v8.getHeapSpaceStatistics();

Parameters: This method does not have any parameters.

Return Value: This method returns an object that contains statistics about version 8 heap space. The returned object usually contains an array of multiple elements, where each element consists of the following fields:

  • space_name: A string represents the name of the heap space.
  • space_size: A number represents the heap space size.
  • space_used_size: A number represents the used heap space size.
  • space_available_size: A number, represents available heap space size.
  • physical_space_size: A number, specifying physical heap space size.

Example 1: The below example illustrates the use of the v8.getHeapSpaceStatistics() method in Node.js.

Filename: index.js 

Run the index.js file using the following command:

node index.js

Output:

[ { space_name: 'read_only_space',
 space_size: 524288,
 space_used_size: 35208,
 space_available_size: 480376,
 physical_space_size: 524288 },
 { space_name: 'new_space',
 space_size: 2097152,
 space_used_size: 975376,
 space_available_size: 55792,
 physical_space_size: 2097152 },
 { space_name: 'old_space',
 space_size: 2330624,
 space_used_size: 2272448,
 space_available_size: 184,
 physical_space_size: 2330624 },
 { space_name: 'code_space',
 space_size: 1048576,
 space_used_size: 571968,
 space_available_size: 0,
 physical_space_size: 1048576 },
 { space_name: 'map_space',
 space_size: 536576,
 space_used_size: 344784,
 space_available_size: 0,
 physical_space_size: 536576 },
 { space_name: 'large_object_space',
 space_size: 0,
 space_used_size: 0,
 space_available_size: 1520180736,
 physical_space_size: 0 } ]

Example 2: The below example illustrates the use of the v8.getHeapSpaceStatistics() method in Node.js.

Filename: index.js 

Run the index.js file using the following command:

node index.js

Output: 👁 Image
Reference: https://nodejs.org/api/v8.html#v8_v8_getheapspacestatistics

Comment

Explore