can not release item which i am using in onItemAdd

  • Thread starter Thread starter Vinayakc
  • Start date Start date
V

Vinayakc

Hi all,

I used OnItemAdd((IDispatch* m_Item)) function to parse every incoming
message come to my inbox.
I got event for each incoming mail. But i can not understand where i
can release this item. It leaves on memory leak in my application.
I unadvise this event in my onDisconnection() function as
AddItemAppEvents::DispEventUnadvise((IDispatch*)m_Item);

Please help me asap.

Thanks and regards
Vinayakc
 
Unless you AddRef the Item variable passed to your event handler, there is
not reason to Release it at any point.
What is m_Item? Is it MailItem or Items object?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
HI Dmitry,
Thanks for the reply.
I declared m_Item as

CComPtr<Outlook::_Items> m_Item;

in my plugin class .h file.

I create event sink as

SINK_ENTRY_INFO(/*nID =*/ 3, __uuidof(Outlook::ItemsEvents),/*dispid
=*/ 0xf001, OnItemAdd, &OnItemAddInfo)


and my event function's signature is

void __stdcall OnItemAdd(IDispatch* Items);

In my OnConnection() function I wrote
AddItemAppEvents::DispEventAdvise((IDispatch*)m_Item,&__uuidof(Outlook::ItemsEvents));

and in
OnDisconnection() I wrote
AddItemAppEvents::DispEventUnadvise((IDispatch*)m_Item);
m_Item.Release();

and my event function looks as follows:

void __stdcall CIPPlugin::OnItemAdd(IDispatch* Items)
{

static int i = 0;
ATLTRACE("Called for Incoming mail for %d times\n", ++i);
CComQIPtr<Outlook::_MailItem> pMailItem(Items);
CComPtr<Outlook::_MailItem> pItem = pMailItem;
CheckForMailFailure( pItem ); //passing mail item to some other
function.
}

This leaves memory leak when i close outlook.

I could not figure out why it is happening.

Please help me.

Thanks again
regards
Vinayakc
 
How does the leak manifest itself? What happens if fyou remoce all of your
cdoe from OnItemAdd()?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Yes Dmirty, If i removed all the code from OnItemAdd() then also it
gives memory leak. When I removed the OnItemAdd event from the code
then only it shows no memory leaks. Please help me. i Can not
understand why it is hapenning.

Thanks
Vinayakc
 
Back
Top