UI Memory Leaks (WPF & Silverlight)

A good read about memory leaks in WPF and Silverlight. Most of the UI memory leaks are evolved around events registration with no unregistrating them which causes the GC not to collect objects.

 

Here are the main causes:

 

  1. Event handlers to objects in parent windows
  2. Registering to events from static objects
  3. Using timers
  4. Data binding
  5. Changing the Text property of a text box (unlimited undo operations)

 

If you ever used a composite approach (like Prism) and EventsAggregators you may have come to appreciate the weak event pattern and the weak reference.

 

Anyway, here is a good read regarding these leaks:
Memory leaks with a demo app explained
Red-Gate PDF memory management / profiling

Developer