none
Ensuring a form is removed from memory RRS feed

  • Question

  • I have recently discovered my C# winforms app has a few memory leaks (using dotTrace). After some research, I found that the IDisposable interface should sort this out for me.

    So I have implemented IDisposable in my app, with limited success. It has helped in some areas (Printing), but not others.

    One area it has not helped with is forms. Form stay in memory after closing, and will create multiple instances of it in memory if I open the form again. One thing I have found with dotTrace is that in the "Incoming References" lists a lot of events (see screenshot).

    Right now I'm kind of guessing that these events are preventing the form from being completely removed from memory. Thus, I need to "Unload" the events (by using the -= thing).

    I have working on this for some time now, and it will take me quite some time yet, as the events have not been loaded in a simple way - they are often loaded in other classes. Before I get carried away with this, I want to make sure I'm on the right track. Is unloading all these events likely to let the form unload from memory?

    If so, then fine, I'm happy to do the work to fix this memory issue. If not though, what is likely to be stopping it from unloading?

    Thanks.

    Monday, April 9, 2012 12:12 AM

Answers

All replies