If you declare an object outside the loop
Outlook.ContactItem NewCont = null;
and then instantiate instances of it within the loop you are only creating
one object. You are assigning an instance of that object each time through
the loop, then you set it to null/release. Next time through you are just
instantiating another instance of that object.
If you declare the object inside the loop you create one object each pass
through the loop, then instantiate it then release it.
Those 2 are not identical scenarios.
If you don't release the objects then they remain in memory until some
undetermined time in the future when the garbage collector finally runs
after the items go out of scope. The RPC channels remain committed until
those objects are released. Therefore you get the errors you described.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
"spottedmahn" wrote in message
...
Hi Ken, thanks again for the reply.
I'm still not clear on your analysis of declaring NewCont outside the
loop.
Whether I put NewCont inside or outside the loop N objects will be
created.
The point of the loop is to take a Outlook Contact and create a Custom
Contact Object. Therefore for every Outlook Contact object there will be
one
Custom Contact Object.
So if I have 200 Outlook Contacts in a MapiFolder the above code would
return a ListCustomContactObject whose count is 200. Make sense?
As for setting each object to null I'm unclear on how that would effect
anything. With each iteration of the loop the variables are re-assigned
to
other objects.
So on Pass 1 Contact = X, then on Pass 2 Contact = Y. Nothing points to X
anymore.
I'm not trying to be combative I'm just trying to understand.
Thanks for you input,
Mike D.