On 03/19/2014 04:39 PM, Kyle Huey wrote:
Short of not implementing things in JS, what ideas do people have for fixing these issues? We have some ideas of how to add helpers to scope these things to the lifetime of the window (perhaps by adding an API that returns a promise that is resolved at inner-window-destroyed to provide a good cleanup hook that is not global) but that doesn't help with objects intended to have shorter lifetimes. Is it possible for us to implement some sort of useful weak reference in JS?
The general principle of GC is that an object is removed when doing so could have no visible effect.
What if these DOM nodes could use a special class of observers / listeners that automatically set themselves aside when the node is deleted from the document, and re-instate themselves if the node is re-inserted in the document? Similarly for when the window goes away.
Then your behavior would be well-defined regardless of when GC happens or doesn't happen.
People always want the GC to help them sort out these sorts of problems; but a good GC is tightly tuned for its workload, and trying to adapt it to serve similar purposes is generally not a path to happiness.
It's better to identify the points at which an observer becomes useless --- hence my suggestion that element insertion and removal be the trigger for the corresponding observers / listeners.
_______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform