Application and Events
Does anyone know if Foundry's
Application
(or the browser itself) does anything magical to clean up after events registered on the html elements created by that application?
I've a vague memory that this is one of the things jquery was good for, and that unless you explicitly clean up manually registered events, you've got potential for a memory leak. I don't have any good sources for that and I'm pretty fuzzy on browser memory and performance matters, but I wondered if anyone more knowledgable than me has taken a look at such things.30 Replies
🧵
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
there's not like some
element.unregisterAllListners
?Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Alright next question, I've done some reading about garbage collection in the browser and the thing that stuck with me is something to the effect of:
The memory of the element can't be cleaned up because there's still an event listener registered to itFull disclosure, i have about 5% confidence in that memory So the browser is smart enough to know that when an element is nuked via replacing
innerHtml
, its old event listeners are useless and thus can be nuked as well?Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
hypothesis: it would only be noticable if the events were registered without jquery because, to my limited understanding, that's one of jquery's claims to fame
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i'm failing pretty hard at googling this...
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I tried this a long time ago and what I saw concerned me, but I realized I had no real knowledge of what I was looking at and wasn't feeling frisky that week 😛
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
So it sounds like...
1. element created
2. events are registered on that element
3. time passes
4. innerHtml change causes old element to be destroyed
5. old element being destroyed destroys event listeners on said element
6. event listeners being destroyed means that the callbacks are no longer referenced
Therefore... everything is garbage collectable.
7. repeat from 1.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
The whole "no references to those elements" is what trips me up. Because sometimes I necessarily have a reference to that element in my event handler callback... So like... I do still have a reference there, but it's kinda circular?
maybe some day i'll learn more about profiling and do that experiment again ¯\_(ツ)_/¯
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
interesting
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
thanks @ghost 🙂
@calego gave LeaguePoints™ to @ghost (#4 • 634)
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
that feels expensive
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
tfw you just want to have your cake and eat it too
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
makes sense, plus they're probably smart enough to wait until its likely that they can run without disruption
very interesting
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
gotchya, thanks
that explains why there's not a million 'gotchyas' blog articles talking about this interaction
@calego gave LeaguePoints™ to @mouse0270 (#27 • 97)
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View