Vote early, vote often! When you help pick the links, you'll like DZone better. Login and vote now.
By alashcraft
via davybrion.com
Submitted: Aug 17 2008 / 20:26
Events in .NET are very useful. But if you’re not careful, they might prevent objects from being removed from memory by the Garbage Collector (GC). Let’s call an object that publishes an event a Publisher and an object that subscribes to an event a Subscriber. If a Subscriber subscribes to a Publisher’s event, the Publisher will indirectly hold a reference to the Subscriber (because of how events in .NET are implemented). If the Publisher is an object that will stay around for a long time, this could prevent the Subscriber from being removed from memory when it’s no longer used.
Add your comment