Solve the high memory usage problem caused by the WebBrowser control.

Source: Internet
Author: User
Tags memory usage

Today, we found that the newly written WinForm application occupies abnormal memory. After analysis and testing, we found that it was caused by multiple WebBrowser controls. To facilitate problem description, the following is the simplified code:

Form1.cs:
 
Public partial class Form1: Form
{
Public Form1 ()
    {
InitializeComponent ();
    }

Private void button#click (object sender, EventArgs e)
    {
(New Form2 (). Show ();
    }
}

Form2.cs:
 
Public partial class Form2: Form
{
Public Form2 ()
    {
InitializeComponent ();
    }

Private void Form2_Load (object sender, EventArgs e)
    {
WebBrowser1.Navigate ("http://www.111cn.net /");
    }
}

 

Refer to the following descriptions on MSDN:

Reference content
The WebBrowser control occupies a large amount of resources. After using this control, you must call the Dispose () method to release all resources in time. The Dispose () method must be called on the same thread that attaches an event. This thread should always be a message or user interface (UI) thread.

However, the actual test of the Dispose method does not reduce the memory. At present, no good solution is found. After the test, it is found that different pages are opened in the same WebBrowser control, and the memory remains within a certain range, therefore, avoid creating the WebBrowser control multiple times and try to open the page in the same WebBrowser control.

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.