[enhancement] Add discard-on-disconnect boolean attribute to clean up the element
Backgrounds
Disconnected custom elements are still active and working
Some iterated elements should be discarded after disconnection
The element must be cleaned up on discarding
Features
Add discard-on-disconnect boolean attribute to perform cleaning-up on disconnect
Tasks in disconnectedCallback()
Call super.disconnectedCallback() if exists
Clean up lang-updated event listener _updateEffectiveLang()
Clean up lang-updated event listeners on boundElement associated to this
Disconnect the mutation observer for <html lang> attribute
Notes
The element's disconnectedCallback must call super.disconnectedCallback() and perform its specific cleanup tasks
Memory profiler shows that elements with discard-on-disconnect attributes are garbage collected on disconnection while element without the attributes are not garbage collected
For world-clock element in the demo, it is unnecessary to empty their shadowRoot for garbage collection.
In some cases, it should be required for an element to clean up this.shadowRoot by this.shadowRoot.innerHTML = '' on disconnection to get itself garbage collected.
[enhancement] Add
discard-on-disconnect
boolean attribute to clean up the elementBackgrounds
Features
discard-on-disconnect
boolean attribute to perform cleaning-up on disconnectdisconnectedCallback()
super.disconnectedCallback()
if existslang-updated
event listener_updateEffectiveLang()
lang-updated
event listeners onboundElement
associated tothis
<html lang>
attributeNotes
disconnectedCallback
must callsuper.disconnectedCallback()
and perform its specific cleanup tasksdiscard-on-disconnect
attributes are garbage collected on disconnection while element without the attributes are not garbage collectedworld-clock
element in the demo, it is unnecessary to empty theirshadowRoot
for garbage collection.this.shadowRoot
bythis.shadowRoot.innerHTML = ''
on disconnection to get itself garbage collected.