How to Fix the Memory Leak in IE WebBrowser Control?

后端 未结 18 840
走了就别回头了
走了就别回头了 2020-11-27 05:33

I am trying to embed a WebBrowser Control in a C# Winform Application. This sounds easy enough. However I discovered that the WebBrowser control eats up a lot of memory ever

18条回答
  •  醉梦人生
    2020-11-27 05:57

    I ran into this problem while writing a small "slideshow" application for different intranet pages used by my company. The simplest solution I found was restarting the application after some fixed period of time, an hour in my case. This solution worked well for us because there wasn't a lot of user interaction with the browser.

    Public Class MyApplication
    
        Private _AppTimer As Timers.Timer
    
        Public Sub New()
            _AppTimer = New Timers.Timer()
            _AppTimer.Interval = 1 * 60 * 60 * 1000 '1 Hour * 60 Min * 60 Sec * 1000 Milli
    
            AddHandler _AppTimer.Elapsed, AddressOf AppTimer_Elapsed
    
            _AppTimer.Start()
        End Sub
    
        Private Sub AppTimer_Elapsed(s As Object, e As Timers.ElapsedEventArgs)
            Application.Restart()
        End Sub
    
    End Class
    

    This assumes of course that you have a data persistence mechanism in place.

提交回复
热议问题