In short, I have inherited a rather complex application, and I am trying to track a memory leak using a form. Right now, every time a form is closed and a new one is brought up, the old one remains in memory. I found a problem with a static event owned and installed by the control inside the program (apparently, until the static event was installed, no instance of this control was considered inaccessible, even if no one referred to the specified controls). Now I am trying to find the remaining problem.
Using MemProfiler and ANTS Memory Profile, I found out that the root path looks like this:
FormOpenWatch <-- The item which remains active System.EventHandler -- (this as Delegate)._target System.Object[] System.EventHandler -- (this as MultiCastDelegate)._invocationList System.ComponentModel.EventHandlerList+ListEntry -- handler System.ComponentModel.EventHandlerList+ListEntry -- next System.ComponentModel.EventHandlerList+ListEntry -- next System.ComponentModel.EventHandlerList+ListEntry -- next System.ComponentModel.EventHandlerList+ListEntry -- next System.ComponentModel.EventHandlerList -- head PTU.MdiPTU -- (this as Component).events <-- The base application
Does anyone have an understanding of what I can find? I found the Shown event added with the base application and ensured its removal when the form was deleted, but this did not seem to fix the problem.
Thanks so much for any help you can provide.
Edit later: I thought I successfully resolved this several times, and I still have problems. The problem seems to be due to my Plotter class (and various derived classes) having this "public static event MouseEventHandler MultiCursorMouseMove"; event. We have a "cursor" that displays the value and time of the graph at the location of the mouse. Initially, this worked on one graph at a time, but a request was made that allowed the user to switch the mode in which mouse movement moved the graph across all displayed graphs. I wrote the initial call related to EventHandlers since the elements were created, and my pond partner rewrote it to use the static event that is assigned to each structural element. Its path is much wider and works better. All this eliminated a memory leak. Using memory profiling software has shown that every time I try to get rid of a form that contains graphics, I have several cases of "Disposed instance with direct EventHandler roots". In each of them, he shows that the object is either a Plotter or the object that Plotter points to. And in each of them, the base link is that of a list of MultiCursorMouseMove EventList objects. I think that Plotter stays alive because it has this static event, which, in turn, is associated with the Plotters. I was able to verify that MultiCursorMouseMove has a null value through the debugger at the given point due to my Dispose code deleting the event for each Plotter, and yet starting the profiler at this point still shows this chain from MultiCursorMouseMove to these classes.
I have no idea how to fix this now. Is anyone
source share