ActiveX Browser Memory Leak
Posted: Mon Jan 11, 2010 1:29 pm
I create a window with a browser, when opened and closed repeatedly I notice the memory consumption is too high
I created a script to illustrate the problem, It uses a timer to close and reopen the window, watch your windows task manager
How do I completely destroy the browser when the window is closed?
Change the URL if you like, even to a local file
I created a script to illustrate the problem, It uses a timer to close and reopen the window, watch your windows task manager
How do I completely destroy the browser when the window is closed?
Change the URL if you like, even to a local file
Code: Select all
###### Scripts.ini ######
[TestLeak]
Filename=TestLeak.vbs
Procname=TestLeak
DisplayName=Test Leak
Order=100
ScriptType=0
Language=VBScript
Description=Testing
Shortcut=Shift+Q
###### TestLeak.vbs ######
Option Explicit
Sub TestLeak()
Dim Timer, Form, WB
Set Timer = SDB.CreateTimer(2000)
Script.RegisterEvent Timer, "OnTimer", "TestLeakTimer"
Set Form = SDB.Objects("TestLeakWindow")
Set WB = SDB.Objects("TestLeakWebBrowser")
If Not (WB Is Nothing) Then
WB.Common.DestroyControl
Set WB = Nothing
Set SDB.Objects("TestLeakWebBrowser") = Nothing
If (Form.Common.Visible) Then Exit Sub
End If
If Not (Form Is Nothing) Then
If Not (Form.Common.Visible) Then Script.UnregisterEvents Timer
Script.UnregisterEvents Form
Form.Common.Visible = False
Form.Common.ControlName = ""
Set Form = Nothing
Set SDB.Objects("TestLeakWindow") = Nothing
Exit Sub
End If
Set Form = SDB.UI.NewForm
Form.Common.SetRect 50, 50, 600, 400
Form.Common.MinWidth = 400
Form.Common.MinHeight = 300
Form.FormPosition = 4
Form.StayOnTop = False
Form.Caption = "Test Leak"
Form.Common.ControlName = "TestLeak"
Set WB = SDB.UI.NewActiveX(Form, "Shell.Explorer")
WB.Common.Align = 5
WB.Common.ControlName = "WB"
SDB.Objects("TestLeakWindow") = Form
SDB.Objects("TestLeakWebBrowser") = WB
WB.Interf.Navigate "google.com"
Form.Common.Visible = True
End Sub
Sub TestLeakTimer(Timer)
Script.UnregisterEvents Timer
Call TestLeak()
End Sub