WebBrowser 占得内存释放不了
private void timer2_Tick(object sender, EventArgs e)
{
wbs1 = new WebBrowser();
wbs1.Navigate(@"http://www.taobao.com");
int h = 0;
while (h < 10)
{
System.Threading.Thread.Sleep(500);
h++;
Application.DoEvents(); }
wbs1.Dispose();
wbs1 = null;
}
private void timer2_Tick(object sender, EventArgs e)
{
wbs1 = new WebBrowser();
wbs1.Navigate(@"http://www.taobao.com");
int h = 0;
while (h < 10)
{
System.Threading.Thread.Sleep(500);
h++;
Application.DoEvents(); }
wbs1.Dispose();
wbs1 = null;
}
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);IntPtr pHandle = System.Diagnostics.Process.GetCurrentProcess().Handle;
SetProcessWorkingSetSize(pHandle, -1, -1);另外可以手动回收以下垃圾
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();虽然不能回到navigate之前的状态,但基本可以接受了,你可以试下效果看看
SetProcessWorkingSetSize(pHandle, -1, -1);
没什么效果啊