2010-02-04 26 views
1

我有一個程序,當它打開一個頁面時瀏覽URL鏈接,它增加了內存使用量,並繼續增加。我發現兩三個小時後,它佔據了我的1和半gb內存打開hunderd頁面我該如何解決這個問題。網頁瀏覽器控制與內存增加問題

+0

你能粘貼你的代碼嗎?這聽起來像你正在節省一些資源,併發布它 – Amirshk 2010-02-04 11:04:33

回答

1

根據this answerthe same question,內存在每個頁面請求/加載時增加,但會在一段時間內釋放 - 這意味着它實際上不是內存泄漏。儘量減少應用程序窗口 - 是內存釋放呢?

在這種情況下,你可以嘗試定期通過這個代碼,以修整應用程序的工作集(從this forum thread,由mike_t2e答案):

// In class definition 
[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(); 

// ... 

// Call this when you want to trim the working set 
IntPtr pHandle = GetCurrentProcess(); 
SetProcessWorkingSetSize(pHandle, -1, -1); 
+0

嗨安德斯菲爾德斯塔德, 感謝您的支持。 Regards, Manish。 – 2010-02-05 14:24:53

+0

這不起作用。我做了一個測試,檢查這個線程:http://stackoverflow.com/questions/6147923/webbrowser-memory-problem – Juan 2011-06-27 04:29:53

2

SetProcessWorkingSetSize實際上並沒有釋放任何內存。 它確實增加了將內存轉出到磁盤的概率, 並可能導致GC收集。

我不明白WebBrowser控件的背景下運作,但我已經意識到一兩件事:

我的程序經過500個或多個頁面以及讀取這些新的內容。它很快耗盡了RAM ,並且如果我再次運行通過所有這些頁面運行的相同函數,它只會從Web瀏覽器緩存中讀取,因此只需幾秒鐘即可完成。

這意味着我們只需要清空瀏覽器緩存以釋放RAM。對?我發現 這個解決方案,但它不起作用。

http://support.microsoft.com/kb/326201/en-us

它永諾給我PrtectedMemoryException ...

好了,這怎麼可能,當我關閉我的應用程序內存只有釋放, 當我處理我的網頁瀏覽器它不釋放控制並創建新的?

+0

我想不出如何執行資源提供的代碼。 – atwellpub 2012-03-23 20:47:56

0

RT _>它總是給我ProtectedMemoryException

無論是從項目屬性改變你的平臺x86 - >建立或internetCacheEntry.lpszLocalFileName更換

returnValue = DeleteUrlCacheEntry(internetCacheEntry.lpszSourceUrlName);