更新时间:2022-06-27 00:08:33
常见内存泄漏
你说你正在关闭所有记录集和连接,这很好.
You say you are closing all recordsets and connections which is good.
但是你是在删除对象吗?
But are you deleting objects?
例如:
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 中没有垃圾收集,因此任何未销毁的对象都将保留在内存中.
No garbage collection in classic ASP, so any objects not destroyed will remain in memory.
此外,请确保您的关闭/无操作在每个分支中运行.例如:
Also, ensure your closes/nothings are run in every branch. For example:
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
在重定向之前没有任何东西被关闭/销毁,因此它只会在某些时候清空内存,因为并非所有逻辑分支都会导致正确的内存清除.
Nothing is closed/destroyed before the redirect so it will only empty memory some of the time as not all branches of logic lead to the proper memory clearance.
更好的设计
不幸的是,这听起来网站设计得不好.我总是将我的经典 ASP 构建为:
Also unfortunately it sounds like the website wasn't designed well. I always structure my classic ASP as:
<%
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>
希望这能有所帮助.