- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
NodeJS - v8.getHeapStatistics() Method
The NodeJS v8.getHeapStatistics() method is used to retrieve the statistics about the heap that is derived from the v8 version. This method returns statistics about the heap such as total heap size, used heap size, heap size limit, total available size, etc.
The getHeapSpaceStatistics() returns the statistics based on the spaces in a system, whereas the getHeapStatistics() method retrieves the statistics for the whole system.
Syntax
Following is the syntax of the NodeJS v8.getHeapStatistics() method −
v8.getHeapStatistics()
Parameters
This method does not accept any parameters.
Return Value
This method returns an object that contains statistics about the heap that is derived from the v8.
Following are the properties that contain in the returned object.
total_heap_size − This property specifies the total heap space size.
total_heap_size_executable − This property specifies the total heap size that is available for execution.
total_physical_size − This property specifies the total physical size available on the disk.
total_available_size − This property specifies the total size that is available to the system.
used_heap_size − This property specifies the heap size that is used
heap_size_limit − This property specifies the limit of the heap size for a user/application.
malloced_memory − This property specifies the memory that is allocated to the application.
peak_malloced_memory − This property specifies the max limit of the memory that is available for the application.
does_zap_garbage − This is a Boolean value 0/1 that tells the system if -- zap_code_space option is enabled or not.
number_of_native_contexts − This is the number of top-level contexts that are currently active. An increase in this number tells that there might be a memory leak.
number_of_detached_contexts − These are the number of contexts that are detached but not yet collected by the garbage collector. If this number is not zero, then it indicates a potential memory leak.
Example
In the following example, we are trying to get all the statistics of the heap that is derived from v8 using NodeJS getHeapStatistics() method.
const v8 = require('v8'); console.log(v8.getHeapStatistics());
Output
{ total_heap_size: 5369856, total_heap_size_executable: 524288, total_physical_size: 4298984, total_available_size: 17226372488, used_heap_size: 2855168, heap_size_limit: 17230200832, malloced_memory: 8192, peak_malloced_memory: 418904, does_zap_garbage: 0, number_of_native_contexts: 1, number_of_detached_contexts: 0 }
Example
In the example below, we are trying to get the statistics of the v8 heap such as total heap size, used heap size, and heap size limit.
const v8 = require('v8'); let statistics = v8.getHeapStatistics(); console.log("total_heap_size: " + statistics['total_heap_size']); console.log("used_heap_size: " + statistics['used_heap_size']); console.log("heap_size_limit: " + statistics['heap_size_limit']);
Output
total_heap_size: 6086656 used_heap_size: 3769624 heap_size_limit: 17213423616 does_zap_garbage: 0
To Continue Learning Please Login
Login with Google