常见内存泄漏
您说您正在关闭所有记录集和连接,这很好。
但是你要删除对象吗?
例如:
Set adoCon = new
Set rsCommon = new
'Do query stuff
'You do this:
rsCommon.close
adocon.close
'But do you do this?
Set adoCon = nothing
Set rsCommon = nothing
经典 ASP 中没有垃圾回收,因此任何未销毁的对象都将保留在内存中。
另外,确保每个分支都运行 close/nothing 操作。例如:
adocon.open
rscommon.open etc
'Sql query
myData = rscommon("condition")
if(myData) then
response.write("ok")
else
response.redirect("error.asp")
end if
'close
rsCommon.close
adocon.close
Set adoCon = nothing
Set rsCommon = nothing
在重定向之前没有任何东西被关闭/销毁,因此它只会在某些时候清空内存,因为并非所有逻辑分支都会导致正确的内存清除。
更好的设计
另外不幸的是,听起来该网站设计得不好。我总是将我的经典 ASP 构造为:
<%
Option Explicit
'Declare all vars
Dim this
Dim that
'Open connections
Set adoCon...
adocon.open()
'Fetch required data
rscommon.open strSQL, adoCon
this = rsCommon.getRows()
rsCommon.close
'Fetch something else
rscommon.open strSQL, adoCon
that = rsCommon.getRows()
rsCommon.close
'Close connections and drop objects
adoCon.close
set adoCon = nothing
set rscommon = nothing
'Process redirects
if(condition) then
response.redirect(url)
end if
%>
<html>
<body>
<%
'Use data
for(i = 0 to ubound(this,2)
response.write(this(0, i) & " " & this(1, i) & "<br />")
next
%>
</body>
</html>
希望其中一些有所帮助。