簡體   English   中英

Web瀏覽器內存泄漏

[英]Webbrowser Memory Leak

我的程序在c#中使用webbrowser,如果我更改了太多頁面,則會出現內存泄漏問題。 我找到了一些解決方案,但是如果嘗試這些解決方案,例如:

finally
{
GC.Collect();
GC.WaitForPendingFinalizers();

EmptyWorkingSet(GetCurrentProcess());
}

首先,內存恢復正常,但是當我切換到頁面或使用Web瀏覽器時,內存泄漏將從中斷處恢復。 我嘗試了很多事情,但沒有找到解決方案。

此代碼將釋放類似於垃圾回收的內存。 我發現將其添加到計時器以自動執行該過程很有用。

    [DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
    internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);

    [DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
    internal static extern IntPtr GetCurrentProcess();

    private void button1_Click(object sender, EventArgs e)
    {
        IntPtr pHandle = GetCurrentProcess();
        SetProcessWorkingSetSize(pHandle, -1, -1);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM