I observe a node by simply doing
new MutationObserver(callback)
.observe(shape.node, {attributes: true})
As you can see I dont have any references to the observer. The observed node will get destroyed at some point.
Is the memory for the node and for the observer cleaned up? Or do they keep themselves alife? And if so: How can I prevent that from happening? I do not know when the node gets removed.
Ofc I could also observe the parent and disconnect the first observer when the parent has a "child list changed" observed but I would like to avoid that
MutationObserver
s hold a weak reference to the nodes they are observing, and the nodes have a strong reference to the mutation observer. That means that in your case, the only thing referencing the observer is the node object. If the node is GCed, nothing will be referencing the observer so it will also be GCed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With