views:

151

answers:

1

I am building a application with on WM6.1, few question about the resource control. My app is build by vs2008/.NET CF 3.5

one of the window form, I place only one webbrowser control, and run the program,
then open the control panel and view the memory usage of applicationm it grow from 25MB to 29MB,nothing special.

After that, I need place 30 webbrowser control to simulate the repeater to represent some content by following code and re-run the program:

    private void FormTest_Load(object sender, EventArgs e)
    {
        string html ="some words";

        WebBrowser wb;
        for (int i = 0; i < 30; i++)
        {
            wb = new WebBrowser();
            wb.Width = 240;
            wb.Height = 100;
            wb.Top = i * 100;
            wb.Left = 0;
            wb.DocumentText = html;
            this.Controls.Add(wb);
        }
    }

Then , memory usage is grow from 25MB to 31MB. It only cost more 2MB. Maybe these 2MB is not consumed by webbrowser,it because the html content of those 30 webbrowser.

So my question is,

1.On .NET world, is it generated multiple instance of control UI are still only cost one instance resource ?

2.What is the best way to dispose these 30 webbrowser control on form_unload? using GC.Collect();? or .net CF will done for me?

Thanks you very much.

+1  A: 
  1. The application itself also uses memory. So the first WebBrowsers seems like it costs a lot compared to the other 29. So personally I think it's nothing fancy. You might want to consider using less WebBrowsers :)

  2. .NETCF has a garbage collector and will dispose all objects when you exit your application. Please keep in mind that on Windows Mobile, applications can be minimized as well. The WebBrowser control also inherits IDisposable and therefore contains the Dispose method.

Rhapsody