vb释放内存
我有一个主函数,需要无限次调用若干个子函数,每次运行大概一小时后(大概调用5000次),就会出现内存溢出而程序出错的问题,我自己分析原因可能在以下一些地方,但不确定。
第一、
我在子函数里使用了一些excel对象与conn,recordset对象,使用完后都做了set xx=nothing处理
Set xlApp = New Excel.Application
Set xlbook = xlApp.Workbooks.Open(fileName)
Set xlsheet = xlbook.Worksheets(1)
.....
xlbook.Close
Set xlsheet = Nothing
Set xlbook = Nothing
xlApp.Quit
Set xlApp = Nothing
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
.........
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
第二,我在子函数里定义了一些静态自定义结构数组与常规变量,每次都没做释放,不知是否有影响?
dim szSX(1 to 500) as tpSX 'tpSX为自定义Type
dim a as integer
dim b as double
.....
第三,我的子函数里使用到了以下一些API函数
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
测试了两天,还是没有找到原因,请高手指点一下,谢谢!