Microsoft KB Archive/188958

= INFO: Possible Causes for Memory Leaks in MAPI Clients/Providers =

Article ID: 188958

Article Last Modified on 8/18/2005

-

APPLIES TO


 * Microsoft Messaging Application Programming Interface

-



This article was previously published under Q188958



SUMMARY
During testing and deployment of an Extended Messaging Application Programming Interface (MAPI) client or service provider, it may appear that the application is leaking memory. It is often difficult to find the exact cause of a memory leak. This article lists several possible reasons for memory leaks in MAPI client or service provider applications.



MORE INFORMATION
There are several logic errors that may cause this problem. A list of possible reasons follows. This is not a comprehensive list, but it does cover the most common problems developers have run into in their code.
 * Not releasing interfaces.
 * Not freeing returned data (for example, row sets, address lists, and properties)
 * Not allocating using MAPIAllocateBuffer or MAPIAllocateMore.
 * Incorrect reference counting on interfaces you implemented.
 * Not initializing reference counting variable in an interface you implement.

Any memory allocated on your behalf by the MAPI subsystem should be released and set to NULL. This includes pointers to interfaces, structures, and any other data types that MAPI deals with. The common rule of thumb is "If MAPI gives it to you, free it or release it."

Make sure you always use the MAPIAllocateBuffer, MAPIAllocateMore and MAPIFreeBuffer functions to allocate and deallocate memory off of the heap space.

When implementing your own interfaces, be sure to follow the rules of COM as strictly as possible to guarantee minimum memory loss from your application.

Additional query words: kbMsg kbMAPI100 kbMAPI

Keywords: kbinfo kbfaq KB188958

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.