google / CodeCity

Google's Code City is a social programming environment. It offers a comic book inspired virtual world where programmers can write code collaboratively.
https://codecity.world/
Apache License 2.0
188 stars 37 forks source link

$.physical.destroy should reparent children #346

Open cpcallen opened 4 years ago

cpcallen commented 4 years ago

Doing

var grandparent = Object.create($.physical);
var parent = Object.create(grandparent);
var child = Object.create(parent);
parent.destroy();

results in child{proto} being $.garbage, which will then typically result in it being ejected from it's location, cleaned from $.pysicals, and, if it is not otherwise referenced, promptly garbage collected.

cpcallen commented 4 years ago

This is not fixed per se, but as a temporary stopgap a new $.garbage.validate method will attempt to restore the original prototype chain of objects that indirectly inherit from $.garbage (and then call whatever .validate method they would originally have had, and $.physical.validate makes calls to this where appropriate to prevent kids of .destroy()ed physicals from getting evicted and possibly garbage collected for real.

This machinery can go away once .destroy can actually find those children at the time it's called.