obj.dispose 怎麽用
用 dispose 函数的功能是什麽??
Private Function QueryTC_Employee(ByVal beforeDate As Date) As DataSet
Dim SqlDat As SqlDataAdapter, DstTC_Employee As New DataSet()
Dim Sentence As String
Try
Sentence = "select * from TC_Employee where bAvailableStatus=0 and iEmployeeid not in " & _
"(select distinct iEmployeeID from TE_IncomeExpenses " & _
"where convert(char(6),dSetAccountDate,12) <= ' " & Format(beforeDate, "yyMMdd ") + " ') "
SqlDat = New SqlDataAdapter(Sentence, SqlCnt)
SqlDat.Fill(DstTC_Employee, "NeedsTheDataWhichDeletes ")
SqlDat.Dispose()
DstTC_Employee.Dispose()
Return DstTC_Employee ‘在上面用 Dispose 函数,这句能不能返回??
Catch ex As Exception
Return Nothing
End Try
End Function
这样写有问题吗??能不能返回 DateSet 对象??
[解决办法]
应该是资源被释放,对象被销毁,但是暂时没有被回收,这时候访问的结果应该是未定义,你试试 dlzhangln(才高七八斗,学富五六车,改行三四次,月入一两千!) 说的强制回收一下?
[解决办法]
即使DstTC_Employee.Dispose()了,只是标记了该对象已经无用了,还是等待GC收回,而GC不会立即执行收回,当内存紧张时,GC按照世代关系,回收你标记的对象,试下GC.Collect()