O'Reilly logo

C# 4.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detach Your Event Handlers

If you would ask any number of .NET developers with a native programming background about the biggest benefits of the platform, they’ll most likely bring up its automatic memory management capabilities that relieve developers of the burden of manual bookkeeping.

As good as this might sound, there are still some caveats to be aware of. In particular, event handlers tend to be common sources of memory leaks when they’re not maintained correctly. What do I mean by “correct maintenance” of event handlers?

Consider the following piece of code:

image

In the preceding code, we’ve abandoned our Handlers event sink instance by setting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required