Does await in node.js cause memory leaks?

minimum recurrence code:

test.js

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
30211 devel     20   0 1229m 381m  10m S  1.0  9.6   1:36.63 node test.js
-sharp startawait
21729 devel     20   0  867m  23m  10m S  1.0  0.6   1:22.73 node test.js
-sharp 
14498 devel     20   0  867m  24m  10m S  1.0  0.6   1:11.04 node test.js

although it is confirmed that there is an extra await, in front of the recursive call, can you explain why? is it because I am using the wrong posture

Mar.12,2022

The

async function returns a Promise object, and whether it resolved depends on whether the await in it is finished; await blocks the code until the Promise object resolved. In the code, await start (), start () is an async function, which returns a promise, with a pedding state, and await waits for the promise until resolved, causes start to go all the way into the stack, not out of the stack:

awaitpromise resolvedstart:



startpromisepromise


2nodejs:

clipboard.png
clipboard.png

the answer also said tail recursion, some said that promise was not destroyed, but why am I also recursive so that there is no memory leak:

  

A new promise object is generated every time, isn't memory leaked

Menu