3 ms·
V8 does actually check if the outer variables are referenced by the inner function. There's a misconception amongst a disturbing number of programmers that it's
by ZenPsycho 8y ago
V8 does actually check if the outer variables are referenced by the inner function. There's a misconception amongst a disturbing number of programmers that it's impossible to memory leak in a garbage collected language. For some reason I've found this particularly prevalent amongst C# developers, but no language community is immune from it.
In truth there are myriad ways to very casually and accidentally create pools of references that can't be garbage collected. I'll leave finding these as an exercise for the reader to google.
here's an old article by Douglas Crockford about a particular memory leak in IE's garbage collector that persisted for a very long time:
https://crockford.com/javascript/memory/leak.html https://crockford.com/javascript/memory/leak.html
- deleted 8y ago[deleted]
- gsnedders 8y agoRight, that sort of bug in IE is one of the more common types: not properly tracing through C++ objects. It isn't, per-se, a bug in the JS VM, given the JS VM's GC is merely acting on what the external code tells it (especially given IE used a separate heap for DOM objects).
- earenndil 8y agoWhat if the internal function calls eval?
- gsnedders 8y agoIn the simple case in my parent comment? If it's a direct eval call, then the VM has to assume it'll reference every possible variable, and has to keep them around as a result.