and hunting memory leaks
@naugtur, meet.js 2016#coolstory
Objects and structures referenced from global root are copied back in.
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 (changes hidden class)null
doesn't remove the object, it changes the referenceWhat 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
@naugtur
http://naugtur.pl
Subscribe to my newsletter http://naugtur.pl/news and get:
- notifications about events I organize before everyone else (think tickets)
- access to learning resources I produce
- no spam, less than 1 email a month on average