Node.JS memory leak with PM2

前端 未结 2 1264
轻奢々
轻奢々 2021-02-02 02:02

I was running my server with pm2 start ... and pm2 monit was showing me 3GB memory after 2 hours. So I attached memwatch, now I waited for

2条回答
  •  半阙折子戏
    2021-02-02 02:36

    • I was also facing the same issue, but after little research i found that nodejs is not calling the garbage collector when using pm2.
    • So, until PM2 fixes that issue temporary work around is force call garbage collector, using following

    pm2 start app.js --node-args='--expose-gc'

    Above argument --expose-gc will allow us to force call garbage collector from node js, now use following code for force garage collection.

    if (global.gc) {
       global.gc();
    } else {
       console.log('Garbage collection unavailable.  use --expose-gc '
       + 'when launching node to enable forced garbage collection.');
    }  
    

    This will solve PM2 meomry leak problem.

提交回复
热议问题