请问c#,winform的虚拟内存怎么释放 一个winform程序,大致框架是有一个MainForm,MainForm里有一个panel,每次点击菜单时,panel.controls.clear(),然后再在panel里加载需要的子窗体,每点击一次菜单,虚拟内存和内存都增加,现在通过empty.exe这个工具能将内存给释放掉,但是虚拟内存不知道怎么释放了,请大家给给建议。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知我的思路是否有点跑题,不过照 lz 的描述,似乎应该 GC.Collect() 一下吧,强制进行垃圾回收。详情参见 MSDN。虽说不知道对机器有多明显的效果,但至少能够使程序更有效地利用内存吧,我想。 解决了,虽然没有完全消除,但增副不大,基本控制在31m虚拟内存左右解决方案:1,定义一个接口 public interface CustomForm { void EmptyRam(); System.Windows.Forms.Form currentForm { get; set; } }2,让窗体集成这个接口,在EmptyRam中释放和GC.Collect(),eg public partial class AlarmForm : Form, Helper.CustomForm { public AlarmForm() { InitializeComponent(); p_current = this; } public static AlarmForm p_current = null; public System.Windows.Forms.Form currentForm { get { return p_current; } set { p_current = (AlarmForm)value; } } public void EmptyRam() { this.Dispose(); this.Close(); p_current = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }3,在菜单click前调用窗体的EmptyRam方法,自定义form在_panel里 Helper.CustomForm customForm = (Helper.CustomForm)_panel.Controls[0]; customForm.EmptyRam(); 附带用Empty.exe释放内存的代码,empty.exe是Windowsxp和win2003自带的内存管理工具,只有40多K,很好用 System.Diagnostics.ProcessStartInfo p = null; System.Diagnostics.Process Proc; string path = System.IO.Directory.GetCurrentDirectory(); if (!File.Exists(path + "\\empty.exe")) { MessageBox.Show(System.IO.Directory.GetCurrentDirectory() + "\\empty.exe不存在"); } p = new ProcessStartInfo(path + "\\empty.exe", "Hisign.ACS.Main.exe"); p.WorkingDirectory = path;//设置此外部程序所在windows目录 p.WindowStyle = ProcessWindowStyle.Hidden;//在调用外部exe程序的时候,控制台窗口不弹出 //如果想获得当前路径为 Proc = System.Diagnostics.Process.Start(p);//调用外部程序 System.Threading.Thread.Sleep(100); 搞了一天,谢谢wsj1983920,kbryant捧场,各散20,谢谢LaoBai_2006的回答,散60,呵呵 急急急急急急急急急急急急急急急急!!!!!!!!!!!!!缩小tiff影像分辨率 完成自动点击功能 C# 求补码 大家来说说 webcast的讲师吧 vs2005 程序生成的安装包问题(超急啊)??? 我用c#写的ftp登陆程序为什么会很卡? 如何让消息区分窗体? 如何使用Process相关信息取得进程的物理路径? 水晶报表如何过滤分别汇总(特急!) 请教一简单问题! 请问C#中怎样传递消息 删除文件
详情参见 MSDN。
虽说不知道对机器有多明显的效果,但至少能够使程序更有效地利用内存吧,我想。
public interface CustomForm
{
void EmptyRam();
System.Windows.Forms.Form currentForm { get; set; } }
2,让窗体集成这个接口,在EmptyRam中释放和GC.Collect(),eg
public partial class AlarmForm : Form, Helper.CustomForm
{
public AlarmForm()
{
InitializeComponent();
p_current = this;
}
public static AlarmForm p_current = null;
public System.Windows.Forms.Form currentForm
{
get
{
return p_current;
}
set
{
p_current = (AlarmForm)value;
}
} public void EmptyRam()
{
this.Dispose();
this.Close();
p_current = null;
GC.Collect();
GC.WaitForPendingFinalizers();
} }3,在菜单click前调用窗体的EmptyRam方法,自定义form在_panel里
Helper.CustomForm customForm = (Helper.CustomForm)_panel.Controls[0];
customForm.EmptyRam();
System.Diagnostics.ProcessStartInfo p = null;
System.Diagnostics.Process Proc;
string path = System.IO.Directory.GetCurrentDirectory();
if (!File.Exists(path + "\\empty.exe"))
{
MessageBox.Show(System.IO.Directory.GetCurrentDirectory() + "\\empty.exe不存在");
}
p = new ProcessStartInfo(path + "\\empty.exe", "Hisign.ACS.Main.exe");
p.WorkingDirectory = path;//设置此外部程序所在windows目录
p.WindowStyle = ProcessWindowStyle.Hidden;//在调用外部exe程序的时候,控制台窗口不弹出
//如果想获得当前路径为 Proc = System.Diagnostics.Process.Start(p);//调用外部程序
System.Threading.Thread.Sleep(100);