The problem can be repeated with something so simple as this:
void JunkItems_ItemAdd( object Item )
{
if ( !(Item is Outlook.MailItem) )
return;
Outlook.MailItem mailItem = (Outlook.MailItem)Item;
mailItem.UnRead = false;
}
If I take that code and add the following two lines to the end of it, the
exact same problem occurs:
mailItem = null;
Item = null;
If I take add a counter and call the following code after 100 times through
this function, the extra ~2000 handles that were created are cleaned up.
However, JunkItems_ItemAdd no longer seems to be connected; it is never
called again.
if ( itemsAddedSinceGc > 100 )
{
itemsAddedSinceGc = 0;
System.GC.Collect();
}
"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Try setting all your objects to Nothing or null values or releasing them
> each time through a loop. You may also have to explicitly call the garbage
> collector.
>
> --
> 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
>