Skip to content

Closure and Memory Leaks

IT Notes → Javascript @ December 22, 2020

  • Returning a function literal created as an internal object within another function, and assigning it to a variable in the calling application, is known as closure in JavaScript.
  • function leakMemory() {
      var el = document.getElementById('el');
      var o = { 'el': el };
      el.o = o;
    }
  • Accidental closure can create memory leaks as above.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x