Here I asked a theoretical question, what is the fate of a variable in C ++ code when CoTaskMemAlloc was allocated for it?
The scheme is approximately as follows:
C ++ allocate variable memory via CoTaskMemAlloc, give the variable in C # managed code.
In the C # code, the variable is described as being returned from the outside:
[return: MarshalAs(UnmanagedType.LPWStr)] .
Further, the garbage collector in C # theoretically should free up the memory of this variable when it decides that it is no longer needed, but when it does (and whether) it is not obvious.
So the question is, how do you understand in C ++ code whether the memory assigned to this variable is free or not? Null she obviously will not be assigned, if I understand correctly ..
And as I guess it’s not safe to call CoTaskMemFree from C ++ code "maybe a second time".
Unfortunately, about the logic of the work of the CoTaskMemAlloc/CoTaskMemFree in CoTaskMemAlloc/CoTaskMemFree in different situations is written a little less than nothing ..