0

I am new to node and angular development. Recently, I am facing this problem - "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory". Can anyone let me know how to find the function which is consuming most of memory leading to this issue? I am not able to figure out the root cause?

I am using node server (Node.js) : 10.15.0 Typescript: 3.2.2

trincot
  • 317,000
  • 35
  • 244
  • 286
Harry
  • 75
  • 8
  • 1
    Try this solution: https://stackoverflow.com/a/53685009/5537770 – Pryda Jan 26 '19 at 10:37
  • if this is an angular compiled function/method it would be a little tricky to pin down, for example you can disable all your angular components and use one by one untill you hit the error again, then you know which one has the problem – Nikos M. Jan 26 '19 at 10:44

1 Answers1

2

there are some solutions for this.

The easiest with node clinic

You have to:

// install
npm install -g clinic
// run your process and see result
clinic doctor -- node my-process.js
// you can also use bubbleprof for network latency or flame for bottlenecks

When you stop the process or the process ends, doctor will create an HTML report with that information.

Another way to find the problem using standard node args:

// will generate a file isolate-0xnnnnnnnnnnnn-v8.log like (isolate-000001AADA5C7900-v8)
node --prof my-process.js
// to make it human readable
node --prof-process isolate-0xnnnnnnnnnnnn-v8.log > processed.txt

Another way is to:

// run your process with inspect:
node --inspect=0.0.0.0:9229 my-process.js
// then run chrome dev tools and connect it to <IP>:9229
go to this url on your Chrome: chrome://inspect/#devices
// then you will able to profile the cpu and take snapshots of memory usage

PS in the chrome dev tools you will see this in order to open:

open node dev tools

Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73