This repository was archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Interesting impact on other specifications #31
Copy link
Copy link
Open
Labels
Description
whatwg/streams#932 by @ricea brings up an interesting situation. I'm curious what the champions have to say about this, although I don't anticipate any changes to the weak refs proposal because of it.
The summary is:
- A spec is written so that spec-created object
yholds on to a user-provided objectxindefinitely - However, after calling
y.close(),ywill never usex. - Thus, it is currently unobservable whether or not an implementation allows
xto be GCed beforey.
With weak refs, this of course becomes observable. Thus once weak refs are introduced, the spec as-written mandates that x never be GCed before y.
In reaction to this, the spec author should probably change y.close() to null out the internal reference to x explicitly. Then browsers will again be allowed to collect x before y and free up some memory, while still conforming to the spec.
Generalizing, the tricky parts of the situation are:
- Spec authors have to be more aggressive about nulling out internal references than they were before, when such references were unobservable. (Assuming they want to avoid mandating unnecessary memory usage.)
- Implementers now have to be exact in following specs' recommendations on nulling out (or not) an internal reference, since doing so is now observable.
- There are probably many divergences today in memory management strategies between browsers on various APIs of this sort, which may need to be audited now that the strategy is becoming observable.