-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
May return the same HTMLCollection object #706
Comments
Context: whatwg/html#4098. |
This doesn't expose GC as long as the browser holds a strong reference to the returned collections, which might make sense for live collections since they are pretty lightweight (consisting of basically a tag name + JS object overhead). I'm not sure whether existing implementations use strong or weak references. I think changing this should have a larger discussion, if that's desired. So /cc @bzbarsky @tkent-google @dstorey. (Aside: it's funny to think that we could have had a weak reference polyfill for many years, at least in some browsers, just by storing expandos on collections returned by these methods...) |
Browsers don't hold strong references to the returned collections right now, as far as I know. Gecko certainly does not. Live collections cache things (at least in Gecko); they don't recompute on every access. So the overhead of a live collection is:
It's not 100% clear what the desired lifetime of a collection would be if we held strong references to them. Should it basically be tied to the lifetime of the node the collection is rooted at? |
Yeah, I guess so, or a fresh (wrapper) object each time. |
FWIW https://jsbin.com/kabidac/edit?html,console seems to work "as expected" (i.e., a weak ref polyfill) in Edge, but in Firefox and Chrome I can never get the |
If I use a 10s timeout instead of 1s I get For what it's worth, in Firefox you can set the "javascript.options.mem.log" preference to true to get logging in the view shown under "Tools > Web Developer > Browser Console". In this case, I see no GC activity on that page within the 1s timeout, which is why you see the results you see. I'm pretty sure we deprioritize GC activity during and right after pageload to improve responsiveness in Gecko... |
I'd like to change "may" to "must", or leave it "may". |
"must" would prevent the browser from ever collecting them, which also increases costs, right? This is why browsers have the behavior they have now: They avoid creating new collections if they can avoid it, but still get rid of old ones so their listeners don't keep slowing down DOM operations. |
Right. It's worse than "may". |
Where exactly? |
|
Hmm. I thought I had gotten |
https://dom.spec.whatwg.org/#concept-getelementsbytagname has
and variants on that. Per @rniwa this is considered a bug by WebKit these days. It'd be nice to stop exposing GC here to the extent that's still happening and define the lifetime of these objects more properly.
The text was updated successfully, but these errors were encountered: