Script action: Does the object set the object to null, automatically delete all connected event listeners?

Recently, I have found that I am constantly writing deleteEventListeners everywhere, which makes the code pretty dirty. I know that this is the best practice and such, but in general it does not make sense. The garbage collector has to cope with such a simple task, right? Is it really hard to delete all listeners automatically when an object is set to null?

Therefore, I just want to be sure that it is. Does the object set to null, automatically delete all connected event listeners?

Any understanding of this?

UPDATE : In my case, the scenario is as follows: I create an object and attach a bunch of event listeners to it, and then after some time I need to reinitialize this object. Of course, setting this object to zero is much easier than manually disabling each listener. And in most cases, listeners are anonymous functions, which means that this is impossible without code refactoring. When I just reinitialize a variable with a new one, I don't get duplicate listeners, etc., but I'm not sure if the previous value, along with all the listeners, gets garbage collection. It?

+5
source share
2 answers

, null, , . , , . , - clearListeners ..

+4

, , , "" .

0

All Articles