Application and Events

Ccalego10/31/2022
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.
Ccalego10/31/2022
🧵
UUUnknown User10/31/2022
Message Not Public
Sign In & Join Server To View
Ccalego10/31/2022
there's not like some element.unregisterAllListners ?
UUUnknown User10/31/2022
3 Messages Not Public
Sign In & Join Server To View
Ccalego10/31/2022
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
Ccalego10/31/2022
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?
UUUnknown User10/31/2022
Message Not Public
Sign In & Join Server To View
Ccalego10/31/2022
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
UUUnknown User10/31/2022
Message Not Public
Sign In & Join Server To View
Ccalego10/31/2022
i'm failing pretty hard at googling this...
UUUnknown User10/31/2022
2 Messages Not Public
Sign In & Join Server To View
Ccalego10/31/2022
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 😛
UUUnknown User10/31/2022
3 Messages Not Public
Sign In & Join Server To View
Ccalego10/31/2022
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.
UUUnknown User10/31/2022
Message Not Public
Sign In & Join Server To View
Ccalego10/31/2022
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?
Ccalego10/31/2022
maybe some day i'll learn more about profiling and do that experiment again ¯\_(ツ)_/¯
UUUnknown User10/31/2022
3 Messages Not Public
Sign In & Join Server To View
Ccalego10/31/2022
interesting
UUUnknown User10/31/2022
Message Not Public
Sign In & Join Server To View
Ccalego10/31/2022
thanks @ghost 🙂
LTLLLeo The League Lion10/31/2022
@Calego gave :vote: LeaguePoints™ to @ghost (#4 • 634)
UUUnknown User10/31/2022
2 Messages Not Public
Sign In & Join Server To View
Ccalego10/31/2022
that feels expensive
UUUnknown User10/31/2022
Message Not Public
Sign In & Join Server To View
Ccalego10/31/2022
tfw you just want to have your cake and eat it too
UUUnknown User10/31/2022
Message Not Public
Sign In & Join Server To View
Ccalego10/31/2022
makes sense, plus they're probably smart enough to wait until its likely that they can run without disruption
Ccalego10/31/2022
very interesting
UUUnknown User10/31/2022
3 Messages Not Public
Sign In & Join Server To View
Ccalego10/31/2022
gotchya, thanks
that explains why there's not a million 'gotchyas' blog articles talking about this interaction
LTLLLeo The League Lion10/31/2022
@Calego gave :vote: LeaguePoints™ to @Mouse0270 (#27 • 97)
UUUnknown User10/31/2022
2 Messages Not Public
Sign In & Join Server To View