Stack overflow & Memory leaks

Stack overflow when we keep calling functions nested inside of each other and over and over. It happens with Recursion or a lot of functions nested inside of each other.

function inception(){
 inception()
}

If I call inception()

  • Maximum call stack size exceeded.

Memory leak Filled up our memory heap with more and more data.

let array = [];
for (let i=5; i > 2; i++) {
   array.push(i)
}

If the script is run

There are three common memory leak that happen.

  1. Global variable: Hypothetically, while we keep adding variables to the environment, we need more and more memory heap.
  2. Event listeners: Add event listeners and if you never remove them.
  3. SetInterval
setInterval(() => {
  referencing objects
}
  • The objects will never be collected by the Garbage Collector.

Leave a Reply

Your email address will not be published.

ANOTE.DEV