Prep code for JS garbagecollect

...but doesn't work yet so commented out.