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)
...