I was planning on building a WPF MVVM business application framework and I came across many articles when doing research that talk about memory leaks in the WPF platform.
A memory leak may occur when you use data binding in Windows Presentation Foundation
Avoiding a WPF memory leak with DataBinding (Black Magic)
Serious Memory Leaks Plague WPF
Top 5 Memory leaks in WPF and Silverlight
WPF Binding Bug leads to possible Memory Issues
But most of them date back to 2007 and 2008 so I was wondering which of them has been solved and which not.
In other words, what are the possible sources of memory leaks (that might happen) to account for when building my framework or to watch for in general (WPF 4.0, .NET 4.0) ?
Edit: I will try to be more specific. Can i take advantage of the WeakEventManager
and its subclasses to listen for events without having to develop my own solution ?
Edit 2: Even more specific. Can i use the WeakEventManager
to solve the problem of memory leak caused by events in .NET in general and not just WPF ?. If so why is it part of a WPF namespace and not a general .NET namespace ?
Memory leaks can still sneak up, even in the applications of a conscientious developer. There might still be situations where the application generates a substantial number of superfluous objects, thus depleting crucial memory resources, and sometimes resulting in the whole application's failure.
Where are memory leaks found? Explanation: Memory leaks happen when your code needs to consume memory in your application, which should be released after a given task is completed but isn't. Memory leaks occur when we are developing client-side reusable scripting objects.
First that comes to my mind:
The fact that you are considering this before starting is a plus, invest in a good MemoryProfiler and profile your app right from the start on a regular basis and you´ll be fine.
Edit: To comment on your edits: Checking through your links I think you can Isolate three main Topics:
As to your edit concerning weak events, yes this might work. Personally i wouldn´t consider this good practice as it might lead to situations where your model exposing the events you are registering to is cleaned up earlier than you expect it. I´d suggest to walk the extra mile and consciously unregister your handler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With