如何在处理表单后清除内存C# [英] How to clear memory after a form is disposed C#
本文介绍了如何在处理表单后清除内存C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下两种形式。
1.frmNewMain
2。 frmDetailReferrals
这里
表格#1是一直打开的静态表格。
表格#2是通过ShowDialog方法打开的模态表单。
表单#1为表单#2创建实例
Hi,
I am having two forms mentioned below.
1.frmNewMain
2.frmDetailReferrals
Here
Form #1 is the static form which is always opened.
Form #2 is a modal form which is opened via ShowDialog Method.
Form #1 creates instance for Form #2
frmDetailReferrals frmDetail =
new frmDetailReferrals(this, LastOpenedCaseID, "Medication");
frmDetail.ShowDialog();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
最初表格#1为23 MB
表格50 MB
如何删除表格#1以外的所有内存资源
提前致谢
Initially 23 MB for Form #1
After Second Form 50 MB
How to remove all memory resources other than Form #1
Thanks in advance
推荐答案
你不能。您无法控制内存分配:一旦将其分配给应用程序的框架,您就无法强制释放它。
您的代码甚至不会处理第二种形式:那里仍然是对它的引用,因此垃圾收集器不会对它做任何事情。
你不应该试图强迫GC:你为什么要这样做?这根本不正常......
You can't. You have no control over the memory allocation: once it's allocated to the framework for your application, you can't force anything to release it.
ANd your code doesn't even Dispose the second form: there is a still a reference to it, so the Garbage Collector will not do anything with it.
You should not be trying to force the GC anyway: why do you want to do this? It's not at all normal...
这篇关于如何在处理表单后清除内存C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文