Why does the code below cause a memory leak when executed? The error only happens when I use Microsoft Visual Studio 2005 or 2008 in vb.net language. If I use C # is, there is no problem.
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()
How do you know there's a memory leak? How can you have a memory leak with a language that's garbage collected? If you're getting an error message that specifically tells you there's a memory leak, there's probably a problem in the database driver itself, which could have been written in any language. Writing any sort of .NET code against that driver shouldn't cause any problems by virtue of what .NET language you're using though.