Application background
Our platform is a one-time WPF application. We have a “shell” that contains the navigation menu structure, and it hosts our own “page” classes. When you go to a new page, we replace the contents of the shell (essentially).
Problem
So, I work for a company that is working on an extremely large software project. We have a lot of code that we encountered with memory problems.
The problem is that in our application there are many places when events are connected and are never freed. I’m not sure why the developers do this, I assume that they expected the objects to be cleaned every time the user goes to a new "page".
We do not have the ability to refactor each page (in this version). Is there a way with C # to remove all links from an object? (Therefore, so that the garbage collector throws this object along with all its internal links)
We are trying to reclaim this memory, but it’s rather difficult to find objects that still link to our pages (object links) when we have WPF.
We looked at visual and logical trees and used profiling applications to help us manually clean things up (to prove the idea), and it turned out to be extremely complicated.
I leaned back and thought: why are we all doing this to find links to objects, can't we just “dereference” this “page” when it is closed?
What brought me here :)
Any help is much appreciated!
UPDATE 1
The comments asked the following:
Q: Is the application in use. really memory problems? How do they manifest / show up? Or is that memory hanging around until GC2 happens? - Mitch Wheat
A: He has memory problems. If you leave the page (a property that contains the page for the new object), the old object will never be collected by the garbage collector. So the memory just continues to grow. If our company has started working with this application. The first thing we should pay attention to is the introduction of WeakEvent templates and the use of more routed commands in WPF.
UPDATE 2
I was able to come up with my own solution .