4 ms·
Second point is, global variables are not cleared by the garbage collector. So if you continuously add more and more global variables (which are not of future u
by mulrian 9y ago
Second point is, global variables are not cleared by the garbage collector. So if you continuously add more and more global variables (which are not of future use), it will cause a memory leak.
Errr...
- aetherspawn 9y agoI think this is true because they hold a reference in window.
- mulrian 9y agoSure that will prevent gc, but that doesn't mean it's a memory leak
- rootlocus 9y agoIf you're never going to use it again, and you're never going to free it, it's a memory leak.
- Sawamara 9y agoNo, it is not. A memory leak has to grow. Without the leak part, it is just ...allocated memory.
- dspillett 9y agoIt is if the variable is accidentally in global scope due to hoisting if it is not explicitly defined in a finer scope. Not an issue in strict mode, you'll get a reference error instead of an implied global.
- Skinney 9y agoIt's an easy thing to do in JS, it happens if you forget the `var`.
- Klathmon 9y agoonly when not in strict mode, which is becoming more and more rare, especially in javascript codebases (as opposed to one-off scripts)