Detecting Memory Leaks in a Node.js/Express.js Application

I've been dealing with memory problems in my Express.js web app lately. It keeps crashing with the following error:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap
out of memory

Initially, when I launch the service, the memory usage is around 170Mb (according to RES memory on htop). However, as I send requests to it, the memory consumption continues to grow. I've been using memwatch to track what seems like a memory leak, and a memwatch.HeapDiff() shows something like this:

{ before: { nodes: 2093729, size_bytes: 197165296, size: '188.03 mb' },
  after: { nodes: 2491264, size_bytes: 232097040, size: '221.34 mb' },
  ...

It indicates that the app is utilizing 221.34mb for the heap; however, htop reports about 2GB of memory usage when it crashes.

This brings me to the question: if my assumptions are correct, what could be consuming non-heap memory that is still shown as RES memory by htop?

Answer №1

I encountered a similar situation where the reported used memory was significantly smaller than what htop showed.

After investigating, we discovered that it was a small JavaScript memory leak causing the issue, which was resolved after fixing it.

If you're interested in learning how I diagnosed and fixed the memory leak, check out the detailed post I wrote about it here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to incorporate a text box in javascript that displays the retrieved reference count from the database?

I'm currently working on creating a functionality that retrieves rows with the same ID from a database and displays them in a text box. Below is the PHP code I've written for retrieving all the rows: PHP: <?php include_once('pConfig ...

What is the best way to retrieve AJAX post data from the request in Symfony2?

My goal is to efficiently upload a file using jquery-file-upload (blueimp) and include some data in a cross-domain environment. To achieve this, I have utilized code from the basic.html file provided by jqueryfileupload on the client side. Additionally, I ...

React Component for Toggling a Click Event on a Select Tag

I'm currently developing a react app where clicking on a specific text triggers the display of a select tag with several items. However, I've encountered two issues: Upon clicking the text, the select tag appears on ALL list items instead of ju ...

Executing Express Application in Command Line

I am attempting to execute the command 'npm start' in my terminal, but I am facing an issue where I am unable to run the command 'node ./bin/www'. Can anyone provide insight into what may be causing this? I am trying to use Express in m ...

Retrieving information from a deeply nested promise in NodeJS

Looking for pointers on how to make promises work, as I am fairly new to them. None of the variations I have tried so far have triggered the final success/error callbacks or returned the data successfully. export function getData(start, end, tagSet){ l ...

Utilize the Webpack library and libraryTarget settings to establish our own custom library as a global variable

I currently have a library named "xyz" that is being imported as a node module from the npm registry. Now, I want to incorporate it as a library and make it accessible under the global name "abc". To achieve this, I plan to utilize webpack configuration. ...

Discover the joy of reading with wrap/unwrap to consume more content in less

I am experimenting with a 'read-more read-less' feature using a wrap method that currently only works for the 'show more' functionality. So, to clarify, if the text exceeds a certain length, I truncate it and insert a read-more-link ( ...

Invoke a parent method from a nested child component in Vue

After setting up a project with vue-cli using the webpack template, I decided to incorporate a reusable bootstrap modal dialog in the App component. To achieve this, I created a method called showMessage in the App component that handles displaying the mod ...

Tips on decorating multi-chain selection buttons

Our latest project involved implementing multi-select buttons. Due to the complexities of styling select and option tags, we decided to utilize chosen.js for this purpose. <link rel="stylesheet" href="$url_link/css/user_css/chosen.css"> <script t ...

Exploring the contents of a dropdown menu by navigating through a tree structure in React JS

A unique custom component has been developed, featuring a dropdown with a tree-like structure inside that allows users to search for values. However, it seems that the search function only works after reaching two levels of the tree structure. Currently, ...

Tips on creating a new file using Node.js

I wrote a new file using this code snippet: const Image=req.body.Image; const imageName = `frame_${Date.now()}.jpg`; const imagePath = `../images/${imageName}` const imageBuffer = Buffer.from(Image.replace(/^data:image\/\w+;base64,/, '' ...

Looking to send an HTTP request to submit a form within a Node.js application to an external website?

Can someone help me with submitting a form on a different site and receiving a response? I'm having trouble figuring out how to do this. Here is the website I am targeting: Below is my code snippet: var http = require('http'); var options ...

AngularJS encountered an error while attempting to create a module with obfuscated code, resulting in a $injector:

Attempting to obfuscate my angularjs application using mangling is resulting in an error. I have been advised to use ngmin to address this issue. Following this advice, I have successfully used ngmin to properly encapsulate my controller code within an arr ...

Error encountered while attempting to import the mongoose npm module into a React application

I'm encountering an issue in my React project where I am trying to include an npm module within a component. Here's an example: var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test', {useNewUrlParser ...

Tips for configuring page-specific variables in Adobe DTM

Although I have integrated Adobe Analytics for tracking on my website, I am facing difficulty in properly defining the variables. This is how I attempted to define the variable: var z = new Object(); z.abc = true; z.def.ghi = true Despite following the ...

Combining duplicate values in MongoDB using aggregation

In my code, I have an aggregate function that counts the occurrences of a value in the database: let data: any = await this.dataModel.aggregate( [ { $match: { field: new ObjectID(fieldID), }, }, ...

The class .is-invalid transforms into .is-valid when rendered

Currently, I am incorporating bootstrap into my react project. In this case, I have a variable called mobile that needs to undergo validation whenever there is a change in the input field. Below is the code snippet for the component: const EnterMobile = ( ...

Bringing in a script and invoking a function on a specific variable

As a newcomer to Typescript, I've been experimenting with some code I came across online to enhance the appearance of links on my website. <script src="https://wow.zamimg.com/widgets/power.js"></script> <script>var wowhead_tooltips ...

React: Implementing Material-UI Typography with custom inline spacing

Take a look at this code snippet: <Typography className={classes.welcomeMessage} variant="h1"> A <span className={classes.redText}>smart nation </span> approach to <span className={classes.redText} ...

Constructing a form by employing the directive approach to incorporate various input fields

My goal is to create input fields that capture information when the submit button is clicked using the directive method. These values will then be passed as arguments to a function. However, my current code is not functioning as expected. <!DOCTYPE htm ...