2

If I listen for events on obj like this:

obj.addEventListener("click", listener)

Assuming that obj is only referenced from another object (obj2.obj = obj), if at some point of the execution of the program, this reference is removed (obj2.obj = null), will obj get garbage collected or do I need to call obj.removeEventListener("click", listener) first? I don't have a deep understanding of the GC in JS VMs, so I'm not sure if there's some circular dependency introduced by the listener that might keep obj alive forever. Does it depend on additional properties of obj or listener actually is? I know it can get especially complicated with things like listener.bind(this), or even worse listener.bind(obj)...

yewang
  • 585
  • 7
  • 14
  • 2
    Possible duplicate of [If a DOM Element is removed, are its listeners also removed from memory?](https://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory) – Luca Kiebel Feb 07 '19 at 10:52

0 Answers0