general memory handling and AddRef/Release q in MAPI
- From: "Eric" <bauersachs@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Dec 2006 18:55:29 +0100
Is there a general documentation about how and where to free memory or call
Release on an interface? I assume the following:
- ADRLIST and SRowSet structures (which are essentially the same) must be
allocated and freed line by line (or address-entry by address-entry), but
not property by property (within a line / address). Here the documentation
is contradictory: At some pages it says that - opposed to other functions -
ADRLIST memory must be freed individual, but as the documentation says here:
http://msdn2.microsoft.com/en-us/library/ms529120.aspx
only the grey parts in the drawing may be allocated together. But here:
http://msdn2.microsoft.com/en-us/library/ms528625.aspx
they say that even each SPropValue must be allocated (and therefore freed)
separately. Which variant is now true?
- If a function returns with an error (not a warning) then the returned
memory pointer doesn't need to be freed. Perhaps then no memory pointer is
returned, but this is not always documented and just an assumption. - OR -
any memory pointer returned must be freed if it's not NULL. What is best
practice here? Can I make such assumptions?
- Some functions like IMessage::GetRecipientTable() return COM object
pointers (like IMAPITable in this case). Do I have to call Release after
using that object because the AddRef has been made in the call (not
documented)? Or do I have to call AddRef() myself when I get the pointer
before I use any other function on that object? If I have to call AddRef
myself isn't there a chance that the object "goes away" just between the
return of the called function and my call to AddRef? Is there a complete
list of MAPI functions that act this way? Do all functions act identical
regarding this?
- Any function that returns memory pointers must allocate it with one single
MAPIAllocateBuffer call (and more memory with MAPIAllocateMore) and the
caller must free it with MAPIFreeBuffer.
Please comment on each point above.
Eric
.
- Follow-Ups:
- Re: general memory handling and AddRef/Release q in MAPI
- From: Stephen Griffin [MSFT]
- Re: general memory handling and AddRef/Release q in MAPI
- Prev by Date: Re: Server Busy when opening address book in custom form
- Next by Date: Re: Server Busy when opening address book in custom form
- Previous by thread: Re: Server Busy when opening address book in custom form
- Next by thread: Re: general memory handling and AddRef/Release q in MAPI
- Index(es):
Relevant Pages
|