Is there a good reason to manually remove event listeners from object’s events if the reference to the object is going to be lost?
Is there a good reason to manually remove event listeners from object’s events if
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Nope. If you’re looking at code which does this, it’s probably because someone’s read that events cause memory leaks, but not really understood why. (It’s when the event subscriber is prevented from being collected because the event publisher has a reference to it. In your case, it’s the publisher which is becoming eligible for garbage collection anyway, so that problem doesn’t apply.)