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
Calego
CalegoOP•3y ago
🧵
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
there's not like some element.unregisterAllListners ?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
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 it
Full 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
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
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
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
i'm failing pretty hard at googling this...
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
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
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
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
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
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
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
interesting
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
thanks @ghost 🙂
Leo The League Lion
Leo The League Lion•3y ago
@calego gave vote LeaguePoints™ to @ghost (#4 • 634)
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
that feels expensive
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
tfw you just want to have your cake and eat it too
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
makes sense, plus they're probably smart enough to wait until its likely that they can run without disruption very interesting
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Calego
CalegoOP•3y ago
gotchya, thanks that explains why there's not a million 'gotchyas' blog articles talking about this interaction
Leo The League Lion
Leo The League Lion•3y ago
@calego gave vote LeaguePoints™ to @mouse0270 (#27 • 97)
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server