What's the best way to avoid memory leaks in WPF PRISM/MVVM application -


I have a WPF application that is based on PRISM which uses MVVM pattern.

I have noticed that sometimes my thoughts, thoughts, ideas and everything related to them will hang for a long time after their desired lifetime.

A collection was made on an injection related collection, one DispatcherTimer, and another need to store its collection items for a leak to be stored.

I am using a CompositePresentationEvent as it is probably better to subscribe to change the archive, but in other scenarios, I am leaning toward implementing IDisposable and calling the idea of ​​View Displacement method on models

But then there is a need to tell about seeing some when disposing on the idea model, which reduces the complexity of ideas, and even hair ideas in the evening. Let's begin to write.

Ian

Ian

I can tell you that I have experienced that your experience has 100% experience. We have a memory leakage brother, I think.

Unfortunately, whatever I am doing is to do it here.

What we have done is to create an attached property that can manually applying a view to bind a handler for the view model:

  & lt ; UserControl ... General: Lifecycle Management. Close handler = "{binding stop action}" & gt; ... & lt; / UserControl & gt;  

Then there is a method on how to act in our view model:

  Public MyVM: View MODAL {public action CloseAction {get closeActionInternal; }} Private Zero ClosureActionInnal () {// TODO: Stop timer, cleaning, etc; }}  

When my closest method is fire (we have some ways to do this ... it has a tab control UI with "X" on the tab header, ), Just check to see if this view is registered with the affiliate property itself or not. If so, then I call the method referred there.

There is a very intersection of view that the datacontext of a scene is an IDisposable, but at that time it felt better. There is a problem examining DataContext that you may have sub-visual models that require this control. You must either make sure that your watchmaking series is forwarded, settle this call or check out all the graph ideas and see if their datacontaxes are idispensable (UG).

I feel like there is some other framework missing here that strive to reduce this scenario in other ways. You can put a look. It has a system where a View MODEL knows all the sub-visual models and automatically carries out the series things. Specifically, there is an interface called ISupportCustomShutdown (I think it has been said) which helps in reducing this problem.

The best part is, I'm sure, and good memory leakage equipment such as the Redgate Memory Profiler which helps you visualize the object graph and find the root object. If you were able to identify the dispatch timer problem, then I think you are already doing this.

Edit: I forgot an important point in the Delayed Commands, due to one of the event handlers, there is a possible leak of memory, here is a thread about it at Codeplex which tells it

The latest version of the prism (v2.1) has been fixed. ().


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -