and hunting memory leaks
@naugtur, 2024https://naugtur.pl
While I introduce you to the topic, checkout this repository:
github.com/naugtur/js-training-examplesWhat to collect??
young generation | old generation
nursery | intermediate |
| |
+--------+ | +--------+ | +--------+
| object |---GC--->| object |---GC--->| object |
+--------+ | +--------+ | +--------+
| |
Details https://github.com/thlorenz/v8-perf/blob/master/gc.md#heap-organization-in-detail
used to be called Shpes or Hidden classes
V8 docs Hidden Classes and Inline Caching in V8 (2015)var aBoy = { name: "Johny" },
aGirl = { name: "Sue" },
anAnimal = { name: "Garfield" };
aBoy = null;
//Johny can now be garbage-collected
aGirl = { name: "Lucy" };
//Sue can now be garbage-collected
aGirl.ownsAnimal = anAnimal
//we have a new reference to Garfield
anAnimal = null;
//a reference is removed, but it was not the only one
//Garfield can't be garbage-collected
delete
keyword does not free memorydelete
just slows you down (creates new Hidden Class)null
doesn't remove the object, it changes the reference
What if I need thousands of objects for short periods of time? I'm implementing a minigun.
This really is only useful for things like particle animation or UI rendering libraries
@naugtur
http://naugtur.pl