Kebocoran memori di JavaScript
1: Accidental global variables
One of the objectives behind JavaScript was to develop a language that
looked like Java but was permissive enough to be used by beginners. One of the
ways in which JavaScript is permissive is in the way it handles undeclared
variables: a reference to an undeclared variable creates a new variable inside
the global object.
2: Forgotten timers or callbacks
The use of setInterval is quite common in JavaScript. Other libraries provide
observers and other facilities that take callbacks. Most of these libraries
take care of making any references to the callback unreachable after their own
instances become unreachable as well.
3: Out of DOM references
Sometimes it may be useful to store DOM nodes inside data structures. Suppose
you want to rapidly update the contents of several rows in a table. It may make
sense to store a reference to each DOM row in a dictionary or array. When this
happens, two references to the same DOM element are kept: one in the DOM tree
and the other in the dictionary. If at some point in the future you decide to
remove these rows, you need to make both references unreachable.
4: Closures
A key aspect of JavaScript development are closures: anonymous functions that
capture variables from parent scopes. Meteor developers found a particular case
in which due to implementation details of the JavaScript runtime.
Undefined