C # How much memory leakage occurs when webbrowser loads pages? solution Summary

Source: Internet
Author: User

[C #] About webbrowser memory usage increase

In Windows program development, the webbrowser control has been used, and many problems have been found in this control one after another. The most serious problem is that his appetite is too bad, every time a page is loaded, it will eat 10 MB of memory.

Webbrowser is a non-hosted code, and I used the hosted code during development. At first, I optimized the code and found that the effect was not improved.

The last check found the root cause of Microsoft's memory overflow bug. Microsoft provided a patch, but Microsoft claimed that it did not undergo regression testing. However, in any case, this is an official solution, it is also relatively clear. After comprehensive consideration, I used the first and second methods in combination to slim down the webbrowser.

1. Official Solutions

Download http://support.microsoft.com/kb/943510/zh-cn

This method cannot be used in patches for Windows 7.0, and XP. server2003 can be used.

Ii. program solutions
Later, some netizens provided two solutions based on the Program Model:

1. Create a thread, dynamically create a webbrowser, and freeandnil after trying again. The thread will destroy the memory occupied by webbrowser ~

2. Create multiple programs and call Program 2 through program 1 to access the page. After the operation, Program 2 exits and the memory is automatically cleared and recycled, information Interaction between programs can be read and saved through the INI file ~

[Color = Red] [B] 3. Upgrade the running environment solution [/B] [/color]

Some netizens provide the following solutions:

After IE is upgraded to IE8, this bug will no longer exist.
The brother claimed that the generated EXE file is available after the IE upgrade. If it is a source program developed with VB6, it cannot recognize the webbrowser control.
You can modify the registry and register the components to solve this problem:

Save the following text as a. reg file and double-click it to import the registry:

Windows Registry Editor Version 5.00
[Hkey_classes_root \ typelib \ {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}]
[Hkey_classes_root \ typelib \ {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B} \ 1.1]
@ = "Microsoft Internet controls"
[Hkey_classes_root \ typelib \ {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B} \ 1.1 \ 0]
[Hkey_classes_root \ typelib \ {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B} \ 1.1 \ 0 \ Win32]
@ = "C: \ Windows \ system32 \ ieframe. dll"

Webbrowser window auto-scroll:This. webbrowser. Document. Window. scrollto (0, webbrowser1.document. Body. scrollrectangle. Height ); Webbrowser script error message:When a script error occurs on the page, a script error prompt is usually displayed. If you use WB to write a crawler, such prompts may cause the system to be unable to work, the solution is as follows: (1) set the scripterrorssurpressed attribute to true; (2) Enable the IE setting "Internet Options"-"advanced"-select "Disable script debugging"   Webbrowser memory release:WB memory overhead is very high, this problem will be very obvious when opening a lot of web pages continuously, even depletion of memory, the solution I found on the msdn Forum (Source: http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8 ), specific: We recommend that you use this method: puremic

This solution worked for me !!
Thank you so much mike_t2e !!!!!!!

-----------------------------------------------------------------------

Is the memory released when you minimize the app? If so, try this:

-- 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 ();

-- Code to call when you want to reduce the memory

Intptr phandle = getcurrentprocess ();
Setprocessworkingsetsize (phandle,-1,-1 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.