日期:2010-02-11  浏览次数:21009 次

判断一个对象是否被释放我们应用:typeName(conn)="Nothing"(一定要用Nothing不能用nothing,小写结果就不为True了,难道ASP也区分大小写?

以下为引用的内容:
<%
Dim conn'声明
Set conn = Server.CreateObject("ADODB.Connection")'创建
'使用
Set conn = Nothing'释放
%>
站.长站

我们通常用如上的形式来创建一个对象,并使用和释放它,问题是我们怎么去判断一个对象是否已被释放了呢?用isObject可以吗?我们来试下:

以下为引用的内容:
<%
Dim conn
Response.Write(isObject(conn)) '结果为False
Set conn = Server.CreateObject("ADODB.Connection")
Response.Write(isObject(conn)) '结果为True
Set conn = Nothing
Response.Write(isObject(conn)) '结果为True
%>

可见并不能使用isObject来判断一个对象是否已被释放,那我们用varType或typeName函数来试试看:

以下为引用的内容:
<%
Dim conn
Response.Write(typeName(conn)) '结果Empty
Set conn = Server.CreateObject("ADODB.Connection")
Response.Write(typeName(conn)) '结果Connection
Set conn = Nothing
Response.Write(typeName(conn)) '结果Nothing
%>
Chinaz@com

所以,判断一个对象是否被释放我们应用:typeName(conn)="Nothing"(一定要用Nothing不能用nothing,小写结果就不为True了,难道ASP也区分大小写?