开发者

webbrowser control with memory increasing problem

i have a program that navigate the urls links one by one when 开发者_JS百科it open a page it increase the memory usages and continue increasing .i found after two or three hour it occupied 1 and half gb of my memory to open a hunderd pages how can i fix this problem.


According to this answer to the same question, the memory increases at each page request/load, but will be released in a while - which means it is actually not a memory leak. Try to minimize the application window - is the memory released then?

In that case, you could try to trim the working set of the application periodically through this code (from this forum thread, the answer by 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);


SetProcessWorkingSetSize doesn't actually release any memory. It does incease the probabilty of the memory being paged out to disk, and probably cause a GC collect.

I don't understand background workings of WebBrowser control, but I've realised one thing:

My program goes through 500 or more pages and reads new content on them. It hogs the RAM quite quickly, and if I run the same function that runs through all those pages again, it simply reads from webbrowser cache, cause it needs only couple of seconds to complete.

It means that we only need to clear browser cache in order to free RAM. Right? I found this solution, but it doesn't work.

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

It allways gives me PrtectedMemoryException...

Ok, so how is it possible that the memory is freed only when I close my application, and it's not freed when i dispose my webbrowser control and create new one?


RT _> It allways gives me ProtectedMemoryException.

Either change your platform to x86 from project properties -> build or replace

returnValue = DeleteUrlCacheEntry(internetCacheEntry.lpszSourceUrlName);

with internetCacheEntry.lpszLocalFileName.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜