积极答复者
关闭窗体释放内存

问题
答案
-
dear
不管做啥窗体都一样,不要随意的自行调用GC.Collection,你的窗体若有可能被调用,那表示关闭的次数也会多,GC.Collection被调用的次数也会多;就交由系统去决定该物件是不是真的被释放吧,不然重新实例化一个物件更是消耗资源的
秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
- 已标记为答案 Bob ShenModerator 2012年5月29日 8:53
全部回复
-
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; namespace EnterpriseMS.ClassItem { class MemoryClearClass { [DllImport("kernel32.dll")] private static extern bool SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); public void FlushMemory() { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); } } }
这个方法可以马上释放,但我并不清楚这样对计算机内存是否有害。请帮我提提看法。谢谢!Raymond
-
-
dear
不管做啥窗体都一样,不要随意的自行调用GC.Collection,你的窗体若有可能被调用,那表示关闭的次数也会多,GC.Collection被调用的次数也会多;就交由系统去决定该物件是不是真的被释放吧,不然重新实例化一个物件更是消耗资源的
秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
- 已标记为答案 Bob ShenModerator 2012年5月29日 8:53