Search code examples
c#compact-framework

Best way to clean resources in .NET compact framework


I have many forms on an solution in .Net compact framework using all the singleton pattern described in Implementing the Singleton Pattern in C# (the 4th version). Some forms are only used very sparingly, while other i must maintain it through very long times. And since i have some memory/processor constraining issues, i need to know what would be the best way to clean resources, using an form.Dispose() or some other method.


Solution

  • You're writing that "other I must maintain it through very long times". I'm assuming that you need to access resources on that form. Is that really neccesary? A form is basically meant to perform as placeholder for input elements and showing data, not to be used as a variable container.

    Besides, you don't need to explicitly call Dispose() on a form, when Show()n the Garbage Collector itself will do that:

    http://msdn.microsoft.com/en-us/library/aw58wzka.aspx

    Dispose will be called automatically if the form is shown using the Show method. If another method such as ShowDialog is used, or the form is never shown at all, you must call Dispose yourself within your application.