Debugging memory leak in express application

Viewed 279

I have a memory leak in my express application. The RSS memory starts at around 80Mb and grows slowly over time to reach around 2-3Gb over a couple of days. I have tried using the --inspect flag to start the process and debug in chrome inspector but not able to find out the exact issue. The Object allocation over a period of time is not that high in this case. The highest memory consumption is by strings as one can see in the attached screenshot. Can anyone point me in the right direction to fix this leak?enter image description here

I have also attached the RSS graph. The decline in memory is due to shutting down the server. enter image description here

Platform: Linux - Ubuntu 18.04.5

1 Answers

Well, it was a native module sharp leaking memory. It's being used in the application for image processing. We need to run the application with libjemalloc which works better with freeing the unused memory back to the OS. We can set the memory allocator by using the following command:

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1
Related