VB6 Memory leak from Interop object

Viewed 98

I have an activeX interop control that is used in an old VB6 application. The ActiveX control is a gridview component and it loads a few hundred thousand records, eating up approx 300MB of Memory every time its started.

Eventually VB runs out of memory.

The interop control is referenced like a normal activex control and loaded using the following code

dim withevents gridview as vbcontrolextender
dim withevents uv as applicationlistcontrol.appgrid
dim imc as applicationlistcontrol.iappgrid

private sub form_load

set gridview = Controls.Add("Applicationlistcontrol.appgrid", "ApplicationListView", me)
set uv = gridview.Control
set imc = uv
imc.FillGrid '(Calls the C# control and loads data into grid)
end sub

private sub form_unload
set imc = nothing
set uv = nothing 
set gridview = nothing 
end sub

The memory is also kept when exiting the application and returning to VB6 IDE and next time its started, another 300 MB get chewed up.

This is the function that loads the data:

using (SqlConnection connection = new SqlConnection(_connectionString)) 
{ 
    connection.Open(); 
    using (var command = new SqlCommand("SELECT * FROM APPLICATION_LIST WHERE APPLICATION_TYPE_ID = 1", connection)) 
    { 
        using (var table = new DataTable()) 
        { 
            table.Load(command.ExecuteReader()); 
        } 
    } 
} 

GC.Collect(); 
GC.WaitForFullGCComplete(); 
return null;
0 Answers
Related