J
Jerry
I have a simple subroutine (see below) which reads a table and populates the items of a combobox. As the subroutine is executed, I'm watching the taskmanager and the memory in use increases; however, once I get to the Error_Exit: logic and start to close and dispose my memory variables, the memory is not released and does not decrease in the task manager. Why is that? Eventually, my program is giving me "Insufficient memory" errors.
****************************************************************************************
On Error GoTo Error_Handling
Dim cnn As New Odbc.OdbcConnection
Dim cmd As New Odbc.OdbcCommand
Dim rdr As Odbc.OdbcDataReader
cnn.ConnectionString = "dsn=" & accpac_companyid
cnn.Open()
cmd.Connection = cnn
cmd.CommandText = "select schedkey, scheddesc from cssktb order by schedkey"
rdr = cmd.ExecuteReader
Do While rdr.Read
combo.Items.Add(rdr("schedkey").ToString.Trim)
Loop
Error_Exit:
If Not IsNothing(rdr) Then
rdr.Close()
cmd.Connection.Close()
cmd.Dispose()
cnn.Close()
cnn.Dispose()
End If
rdr = Nothing
cmd = Nothing
cnn = Nothing
Exit Sub
Error_Handling:
Select Case Err.Number
Case Else
MsgBox("The following error occured in LoadSchedules()" & vbCrLf & Err.Description)
End Select
Resume Error_Exit
****************************************************************************************
On Error GoTo Error_Handling
Dim cnn As New Odbc.OdbcConnection
Dim cmd As New Odbc.OdbcCommand
Dim rdr As Odbc.OdbcDataReader
cnn.ConnectionString = "dsn=" & accpac_companyid
cnn.Open()
cmd.Connection = cnn
cmd.CommandText = "select schedkey, scheddesc from cssktb order by schedkey"
rdr = cmd.ExecuteReader
Do While rdr.Read
combo.Items.Add(rdr("schedkey").ToString.Trim)
Loop
Error_Exit:
If Not IsNothing(rdr) Then
rdr.Close()
cmd.Connection.Close()
cmd.Dispose()
cnn.Close()
cnn.Dispose()
End If
rdr = Nothing
cmd = Nothing
cnn = Nothing
Exit Sub
Error_Handling:
Select Case Err.Number
Case Else
MsgBox("The following error occured in LoadSchedules()" & vbCrLf & Err.Description)
End Select
Resume Error_Exit