我继承了一些类似的代码:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim Test As Integer
Dim strCon As String = "Data Source=TestDatabase;User Id=TestUser;Password=TestPassword;"
For Test = 0 To 100000
Dim objDBCon As New OracleConnection(strCon)
Dim objDBCmd As New OracleCommand
Dim objDR As OracleDataReader
Using objDBCon
'Using objDBCmd
objDBCmd.Connection = objDBCon
objDBCmd.CommandText = "SELECT * FROM nominal_incident where rownum = 1 "
objDBCon.Open()
objDR = objDBCmd.ExecuteReader
'End Using
End Using
Next
Catch ex As Exception
'Handle the exception. It is not absorbed.
End Try
End Sub
这会导致内存泄漏吗?我希望看到如下 Using 语句:
Using objDBCmd
End Using
ASP.NET 进程逐渐增长(超过 1 GB),WinDBG 显示堆上有 OracleCommand 对象(尽管没有我预期的那么多)。我想 OracleCommand 可以保留会导致进程大小增长的其他资源。