Should MutationObservers be removed/disconnected when the attached DOM node is removed like removeEventListener for events?

半城伤御伤魂 提交于 2019-12-09 04:29:28

As I was researching the topic more, it seems that I came across the answer.

In the eyes of garbage collection, MOs are tightly coupled with the DOM elements, whereas their descendants are loosely coupled. So it appears that you remove the DOM element whenever, and garbage collection is supposed to handle the rest.

Official answer https://dom.spec.whatwg.org/#garbage-collection:

4.3.4. Garbage collection

Nodes have a strong reference to registered observers in their registered observer list.

Registered observers in a node’s registered observer list have a weak reference to the node.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!