.NET Webbrowser Control and Dispose()

后端 未结 3 1436
生来不讨喜
生来不讨喜 2021-01-14 01:03

I know this is a hot discussed topic with many questions and answers but I still do not find the solution for the following problem:

I have a multi-tab application.

3条回答
  •  轮回少年
    2021-01-14 01:58

    This seems to be a GarbageCollector-Problem. You can try to use the dirty way of System.GC.Collect(), just calling the GarbageCollector to free memory, but this is not a good way to solve the problem.

    Of what you told, this seems to be a Pointer-problem. If you declared the Connection as a global variable, you have to detach the connection from the tab befor you can close/dispose the tab itselve. The event Me.Closing shuld help you to do so. If the Pointer stays open, the tab as an object is still connected on the Connection and will (not realy shure if/when) not get cleaned by the GC.

    If you can clarify your way of duplicating/referencing the connection, I could give a more detailed answer.

    EDIT: after a while of research my worries became true - there is a problem with caching under IE (>5 as far as I know). http://social.msdn.microsoft.com/Forums/ie/en-US/88c21427-e765-46e8-833d-6021ef79e0c8/memory-leak-in-ie-webbrowser-control

    Suggestions are:

    • calling GarbageCollector manually

    • limit MemUsage (can result in application-crashes and also just writes the pages to disk)

    • about:blanc to override cache-entries

    • calling C++ methods to override the cache (WinINet - all I have found resulted in some ProtectedMemory-Errors - maybe this C# WebBrowser control: Clearing cache without clearing cookies works)

    • using C++ and WinINet (I don't know any real .Net implementation and it may also have this memory leak)

    • using alternatives to IE like gecko (Mozilla) - https://bitbucket.org/geckofx/

提交回复
热议问题