How to use IMalloc::Free?
Asked Answered
I

2

2

I'm using ICommandText::GetCommandText method. According to the MSDN documentation (http://msdn.microsoft.com/en-us/library/ms709825(v=VS.85).aspx) I need to use IMalloc::Free to release the memory allocated for LPOLESTR *ppwszCommand output parameter.

How do I use this interface to do that?

Implantation answered 20/6, 2010 at 14:5 Comment(0)
M
3

Just pass it to CoTaskMemFree, it's wrapping the same default OLE allocator CoGetMalloc is exposing.

CoTaskMemAlloc/Free are convenient shortcuts to IMalloc interface of the default OLE allocator so you can skip the cumbersome interface altogether.

Milly answered 21/6, 2010 at 15:49 Comment(4)
Cool, but is there any reference confirming that really CoTaskMemFree() is the same as IMalloc::Free()?Sarcophagus
Raymond Chen has an explanation and more on the internals: blogs.msdn.com/b/oldnewthing/archive/2004/07/05/173226.aspxMilly
@Milly the link is broken.Revolutionize
Yes, it's moved to devblogs.microsoft.com/oldnewthing/20040705-00/?p=38573Milly
S
1

You'll need to retrieve an IMalloc* pointer first - use CoGetMalloc() for that. Once you've got an IMalloc* pointer call IMalloc::Free(), passing the address of the block you want to free. Once you've finished with the IMalloc* pointer call IMalloc::Release() on the pointer or save it somewhere to reuse and free when you no longer need it.

Sarcophagus answered 21/6, 2010 at 6:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.