Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 2.27 KB

allocating-and-releasing-memory-for-a-bstr.md

File metadata and controls

36 lines (26 loc) · 2.27 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Allocating and Releasing Memory for a BSTR
Allocating and Releasing Memory for a BSTR
11/04/2016
bstr
BSTRs, memory allocation
memory deallocation, string memory
memory [C++], releasing
memory allocation, BSTRs
memory deallocation, BSTR memory
strings [C++], releasing
98041e29-3442-4a02-b425-7a4a13e9cc84

Allocating and Releasing Memory for a BSTR

When you create BSTRs and pass them between COM objects, you must take care in treating the memory they use in order to avoid memory leaks. When a BSTR stays within an interface, you must free its memory when you are done with it. However, when a BSTR passes out of an interface, the receiving object takes responsibility for its memory management.

In general, the rules for allocating and releasing memory allocated for BSTRs are as follows:

See also

Strings (ATL/MFC)
CStringT::AllocSysString
SysAllocString
SysFreeString