The repository contains 4 types of NodeJS memory leaks and the solution to each of them. While NodeJS is very popular server side technology and easy to get started with, it needs to be managed with caution as memory leaks can happen very easily. The 4 most common types tackled here are
You need NodeJS installed in your system to run the application. To be able to test for leaks, there are multiple tools available for load testing. The one we are going to use here is autocannon. Also to visualize the leaks, we are going to use one handle tool, Clinic.js. First install both of these tools globally.
npm i autocannon -g
npm i clinic -g
After that run the run.sh
script with flags to start load testing and capturing heap data at the same time. The possible values for -m
are global
, closures
, cache
, promise
./run.sh -f index.js -m cache -d 20
And after the script runs successfully, a new tab will open up in your default broswer with graph of the leaks accumulating over time.
To run the solution, just change the script name.
./run.sh -f solution.js -m cache -d 20
And this time you'd see that the resources are being garbage collected.
Change the method name and try with other types of leaks.
Want to contribute? Great!
To fix a bug or enhance an existing code, follow these steps:
git checkout -b improve-feature
)git commit -am 'Improve feature'
)git push origin improve-feature
)MIT © MD Ahad Hasan
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。