https://github.com/adnanrahic/node-memory-leaks
https://github.com/adnanrahic/node-memory-leaks
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/adnanrahic/node-memory-leaks
- Owner: adnanrahic
- Created: 2022-02-08T20:35:40.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-08T20:38:34.000Z (over 3 years ago)
- Last Synced: 2025-02-07T22:51:19.887Z (5 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Showcasing Node.js Memory Leaks
In order to expose the inspector, let's run Node.js with the `--inspect` flag.
```bash
node --inspect index.jsDebugger listening on ws://127.0.0.1:9229/7fc22153-836d-4ed2-8090-a84a842a199e
For help, see: https://nodejs.org/en/docs/inspector
Sample app listening on port 3000.
```Open up Chrome and go to `chrome://inspect`. Here you can take snapshots of the memory usage.
```bash
open -a "Google Chrome" chrome://inspect/#devices
```
## **Watching Memory Allocation In Real-Time**
You use the `Allocation instrumentation on timeline` option in this case. Select that radio button and check the `Record stack traces of allocations` checkbox. This will start a live recording of the memory usage.
For this use case, I used [`loadtest`](https://www.npmjs.com/package/loadtest) to run 1000 requests against the sample Express app with a concurrency of 10.

For the first few requests, you can see a spike in memory allocation. But it’s obvious that most memory is allocated to the arrays, closure, and objects.