我在 .Net 紧凑框架中的解决方案上有多种形式,使用 Implementing the Singleton Pattern in C# 中描述的所有单例模式。 (第四版)。有些表格很少使用,而另一些表格则必须长期维护。由于我有一些内存/处理器限制问题,我需要知道使用 form.Dispose() 或其他方法来清理资源的最佳方法是什么。
最佳答案
你写的是“其他的我必须维护它很长时间”。我假设您需要访问该表单上的资源。这真的有必要吗?表单基本上是用作输入元素的占位符并显示数据,而不是用作变量容器。
此外,您不需要在表单上显式调用 Dispose(),垃圾收集器本身会执行 Show() 操作:
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.
关于c# - .NET 紧凑框架中清理资源的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4993797/