Re: automation error

From: Ken Slovak - [MVP - Outlook] (kenslovak_at_mvps.org)
Date: 06/22/04


Date: Tue, 22 Jun 2004 09:29:22 -0400

Although there are leaks when using any iterative loop with Outlook objects
and collections. The problem is that Outlook creates internal variables for
each pass through the loop and doesn't release them until the procedure
ends, even if you explicitly release any explicit variables you are using.
The problem can be minimized but not eliminated by not using compound dot
operators. Instead of using oFolder.Items(2) for example setting an Items
collection object and using that would help a little.

FWIW I almost always use For Each loops, which are faster than counted
loops, unless the collection might be large (say over 1500 items). Then I
use CDO 1.21 or Redemption to process the collection using a loop or a
MAPITable and that's not only faster but has fewer memory leaks.

-- 
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Thomas Wetzel" <wetzel@wisco.de> wrote in message
news:cb7f9p$i01$07$1@news.t-online.com...
> Hello Ret,
>
> > Set iItems = fFolder.Items
> > For Each iItem In iItems
> >     'here I do something with the items
> > Next
>
> Do never, NEVER use For each loops in Outlook.
>
> Outlook has memory leaks! Always count the items and then set the item
like:
>
> set myItem=myFolder.items(2)
>
>
> -- 
>
> Thomas Wetzel
> Synchronize or backup your Outlook quick and easy.
> www.synchpst.com
>
>


Relevant Pages

  • Re: Problem when Looping through large number on MS Exchange conta
    ... each message explicitly and resetting it to Nothing inside the loop. ... OutlookSpy - Outlook, CDO ... >>> dim oResults as Outlook.Results ... >>> dim oContact as Outlook.ContactItem ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Outlook Automation Problem
    ... Dim objNS As Outlook.NameSpace ... > The error is not coming when I loop through the contacts and add each one ... > is used as the Recipient for Outlook email. ... > Not having access to a network or exchange server makes it a little ...
    (microsoft.public.vb.general.discussion)
  • Re: Filling listbox on custom Contact item 1st page
    ... list box in each objItem as they are being walked thru by the rest of the ... code within the For Each...EndIf loop ... Sue Mosher, Outlook MVP ... If intRowCount> 0 Then ...
    (microsoft.public.outlook.program_forms)
  • Re: Outlook 2003 vba macro
    ... Sue Mosher, Outlook MVP ... > Another way of doing it is to use a for each loop ... 'Move the email Item to the backup folder ... >> Dim objApp As Application ...
    (microsoft.public.outlook.program_vba)
  • Re: Restrict method problem
    ... When you access the subject property, Outlook does not open the ... Can you try to use a for loop instead of while? ... > Set objMinItems = Nothing ... >>> and MAPI Developer Tool ...
    (microsoft.public.outlook.program_vba)