Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7077311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:24:22+00:00 2026-05-28T06:24:22+00:00

Here is the function: Private Sub LoadEmail() Dim loSession As RDOSession = Nothing Dim

  • 0

Here is the function:

        Private Sub LoadEmail()

        Dim loSession As RDOSession = Nothing
        Dim loMessages As RDOItems = Nothing

        Try
            moNDRs = New List(Of NonDeliveryRecord)
            loSession = New Redemption.RDOSession
            loSession.LogonExchangeMailbox(MailAccountName, MailServerName)
            loMessages = loSession.GetDefaultFolder(rdoDefaultFolders.olFolderInbox).Items
            Dim Counter = 0
            For Each loMessage As RDOMail In loMessages
                Counter += 1
                moNDRs.Add(CreateNDRRecord(loMessage))
                Marshal.ReleaseComObject(loMessage)
                loMessage = Nothing
                If Counter Mod 100 = 0 Then GC.Collect()
            Next


        Finally
            If loSession IsNot Nothing Then
                loSession.Logoff()
                Marshal.FinalReleaseComObject(loSession)
                loSession = Nothing
            End If

            If loMessages IsNot Nothing Then
                Marshal.FinalReleaseComObject(loMessages)
                loMessages = Nothing
            End If

        End Try

    End Sub

The Message classes uses above are Redemption. If you look in the function above you will see:

If Counter Mod 100 = 0 Then GC.Collect()

Which is what i had to do to fix the problem we are having. I’ve been playing around with memory profilers this morning (ants & dottrace) to see if i could figure anything out but so far everything looks fine. I’m no low level won’t who knows the ins and outs of windgb.

The error i’m getting is:
Error in IMAPISession::OpenEntry: MAPI_E_TOO_BIG

The line where i always get the error is commented in the code below. I always get the error after ~450 iterations.

Is this one of the few times you have to use gc.collect is when your dealing with COM objects?

Here is the CreateNDR function with the line the error happens on:

        Public Function CreateNDRRecord(ByVal voMessage As RDOMail) As NonDeliveryRecord

        Dim loItem As RDOReportItem = Nothing
        Dim loMatches As MatchCollection = Nothing
        Dim loNonDeliveryCode As NonDeliveryRecord = New NonDeliveryRecord
        Dim lsMessage As String = String.Empty


        Try
            loNonDeliveryCode.IsBadMessage = False
            loNonDeliveryCode.MailMessageId = voMessage.EntryID

            'Debug.Print(voMessage.MessageClass.Equals("REPORT.IPM.Note.NDR").ToString())
            If voMessage.MessageClass.Equals("REPORT.IPM.Note.NDR") Then 'error always happens here
                loItem = CType(voMessage, RDOReportItem)
                If voMessage.Recipients.Count <> 0 Then
                    loNonDeliveryCode.EmailAddress = voMessage.Recipients(1).Name
                End If
                loNonDeliveryCode.IsUndeliverable = True
                lsMessage = loItem.ReportText

            ElseIf voMessage.Subject.Contains(mconSeparator) Then
                loNonDeliveryCode.EmailAddress = voMessage.Subject.Substring(voMessage.Subject.LastIndexOf(mconSeparator) + mconSeparator.Length)
                loNonDeliveryCode.ErrorCode = String.Empty
                loNonDeliveryCode.IsUndeliverable = True
                lsMessage = voMessage.Body
            End If

            If loNonDeliveryCode.IsUndeliverable Then

                loMatches = GetErrorType(lsMessage)

                If loMatches.Count > 0 Then
                    loNonDeliveryCode.ErrorCode = loMatches(loMatches.Count - 1).Value
                End If

                Dim loNDRId = GetErrorCode(loNonDeliveryCode.ErrorCode)

                If loNDRId.Count > 0 Then
                    loNonDeliveryCode.ErrorCodeId = CType(CType(loNDRId(0), DataRow).Item("NonDeliveryCodeId"), Integer)
                    loNonDeliveryCode.ErrorDescription = CType(CType(loNDRId(0), DataRow).Item("Description"), String)
                    loNonDeliveryCode.MarkAsInvalid = CType(CType(loNDRId(0), DataRow).Item("MarkAsInvalid"), Boolean)
                Else
                    If voMessage.MessageClass.Equals("REPORT.IPM.Note.NDR") Then
                        loNonDeliveryCode.ErrorCode = String.Empty
                        loNDRId = GetErrorCode(loNonDeliveryCode.ErrorCode)
                        loNonDeliveryCode.ErrorCodeId = CType(CType(loNDRId(0), DataRow).Item("NonDeliveryCodeId"), Integer)
                        loNonDeliveryCode.ErrorDescription = CType(CType(loNDRId(0), DataRow).Item("Description"), String)
                        loNonDeliveryCode.MarkAsInvalid = CType(CType(loNDRId(0), DataRow).Item("MarkAsInvalid"), Boolean)
                    Else
                        loNonDeliveryCode.ErrorCode = String.Empty
                        loNonDeliveryCode.ErrorCodeId = 1
                    End If
                End If

            End If


            Return loNonDeliveryCode

        Catch Ex As Exception
            loNonDeliveryCode.IsUndeliverable = False
            loNonDeliveryCode.IsBadMessage = True
            Return loNonDeliveryCode

        Finally
            If loItem IsNot Nothing Then
                Marshal.FinalReleaseComObject(loItem)
                loItem = Nothing
            End If

            If voMessage IsNot Nothing Then Marshal.ReleaseComObject(voMessage)

            If loMatches IsNot Nothing Then
                loMatches = Nothing
            End If

        End Try
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:24:27+00:00Added an answer on May 28, 2026 at 6:24 am

    There are cases where a program just doesn’t consume enough garbage collected memory to invoke the finalizer thread enough to clean up resources. A trouble-maker is the Thread class for example. It consumes 5 operating system handles but doesn’t have a Dispose() method to release them early. And COM coclasses like the ones you are using, the managed wrapper that the CLR creates for them has a finalizer but doesn’t implement IDisposable. Examples of classes where a user program just can’t effectively or reliably call Dispose().

    GC.Collect() was made for such cases. Also call GC.WaitForPendingFinalizers() since that’s what you really want to happen.

    Your usage of it is correct and defensible. You do have to tune it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: Dim StartString As String = Private Sub Dim EndString As
Here is my function: private void btnSave_Click(object sender, EventArgs e) { wO_FlangeMillBundlesTableAdapter.Update(invClerkDataDataSet.WO_FlangeMillBundles); wO_HeadMillBundlesTableAdapter.Update(invClerkDataDataSet.WO_HeadMillBundles); wO_WebMillBundlesTableAdapter.Update(invClerkDataDataSet.WO_WebMillBundles);
I've got a function here that is meant to look through a list of
Is it possible to have default arguments in MATLAB? For instance, here: function wave(a,
Here is function , <script type=text/javascript> $(document).ready(function() { getRecordspage(1, 5); $(a.page-numbers).click(function() { alert(1); getRecordspage($(this).text(),
$('#selector').click(function() { // here I would like to load a javascript file // let's
Someone posted a great little function here the other day that separated the full
simonn helped me to code an ordered integer partition function here. He posted two
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
I need to pass an url from asp.net load_page to flowplayer javascript function here:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.