Allocating and freeing memory across module boundaries
I'm sure it's been drilled into your head by now that you have to free memory with the same allocator that allocated it. LocalAlloc
matches LocalFree
, GlobalAlloc
matches GlobalFree
, new[]
matches delete[]
. But this rule goes deeper.
If you have a function that allocates and returns some data, the caller must know how to free that memory. You have a variety of ways of accomplishing this. One is to state explicitly how the memory should be freed. For example, the Fo