为什么下面的代码在执行时会导致内存泄漏?该错误仅在我以 vb.net 语言使用 Microsoft Visual Studio 2005 或 2008 时发生。如果我用C#的话,是没有问题的。
Dim strCon As String = "data source=SRV-10G;user id=Test;password=1234"
dim factory as DbProviderFactory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");
Dim conexao As IDbConnection = factory.CreateConnection
conexao.ConnectionString = strCon
conexao.Open()
For cont As Integer = 1 To 100000
Dim comando As IDbCommand = conexao.CreateCommand()
comando.CommandText = "Select * from tabela where campo = " & cont
Dim leitor As IDataReader = comando.ExecuteReader
While leitor.Read
Dim v As String = leitor.GetValue(1).ToString
End While
leitor.Close()
leitor.Dispose()
comando.Dispose()
Next
conexao.Close()
conexao.Dispose()