VB6来自Interop对象的内存泄漏

问题描述

我有一个ActiveX互操作控件,该控件在旧的VB6应用程序中使用。 ActiveX控件是gridview组件,它加载数十万条记录,每次启动时都会消耗大约300MB的内存。

最终VB内存不足。

interop控件的引用类似于普通的activex控件,并使用以下代码加载

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

退出应用程序并返回到VB6 IDE时,还会保留内存,下次启动时,将占用另外300 MB。

这是加载数据的功能

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;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)