Automate COM Object Memory Management

    Related Topics

      See Free COM Object in VBUC Upgrade Options

    Visual Basic 6 will automatically release COM objects when they are not referenced any more.

    .NET automatically handles managed resources but does not release all resources immediately. This difference can cause unexpected behaviors. For example, ADO Connections might remain open longer than in VB6.

    This optional feature will generate explicit code to achieve the same behavior.

    VB6 Code

    Private Sub Command2_Click()
    Set conn = CreateObject("ADODB.Connection")
    conn.Open "northwind.mdb"
    Set rs = CreateObject("ADODB.recordset")
    rs.Open "Customers", conn
    End Sub

    .NET Code

    private void  Command2_Click( Object eventSender,  EventArgs eventArgs)
    {
    ADODB.Connection conn = null;
    ADODB.Recordset rs = null;
    try
    {
    conn = new ADODB.Connection();
    conn.Open("northwind.mdb", "", "", -1);
    rs = new ADODB.Recordset();
    rs.Open("Customers", conn, ADODB.CursorTypeEnum.adOpenUnspecified,
    ADODB.LockTypeEnum.adLockUnspecified, -1);
    }
    finally
    MemoryHelper.ReleaseAndCleanObject(rs);
    rs = null;
    MemoryHelper.ReleaseAndCleanObject(conn);
    conn = null;
    }
    }
    Important Resources

    Download VBUC Free Trial
    Download  Now

    It's time to eradicate VB6
    ROI of Eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    Learn More