Find all addEventListeners without weakReference
Today I made a regular expression to find all addEventListeners that don’t set the useWeakReference to false, this is important because it can save you a lot of references to objects that should have been deleted.
For more information on this topic see the post Grant Skinner wrote about this: gskinner.com
The regular expression:
1 | addEventListener[(a-zA-Z_]*.[a-zA-Z_]*, *[a-zA-Z_]*.; |

THE COMMENTS:
What Luc said 1 hour later:
wa bende toch ok unne nerd
What 1hoog said 10 hours later:
Hey,
Thanks for this. After you searched them you sometimes might find it useful to apply weakreferences to them.
search:
(addEventListener[(a-zA-Z_]*.[a-zA-Z_]*,*[a-zA-Z_]*)(.;)
replace:
$1, false, 0, true);
Greets
Undersound
What jankees said 2 days later:
That's a nice tip! But I don't know if I would do it with search and replace… feels a bit dangerous :)
What Thijs said 3 days later:
I think you shouldn't use weak-reference for eventlisteners. It's much better to remove the listeners when you don't need the object/listener anymore.
When using weak-reference your code is depending on the garbage-collector for cleaning up the system. But you'll never know when (or even if) the garbage-collector will do his job*.
When use weak-reference it can happen that an object is removed by the garbage-collector when you still need it, since you didn't store a reference to the object.
You can try using Casa for removing all the eventlisteners for you. We build our own framework (Temple), based on Casa, that handles and automaticly remove all eventlisteners.
*) I know, there are some tricks to force a garbage collection, but they are dirty.