The following type
CS_VALUE_TYPE class DLL_API ValueType {
public:
const char* char_ptr_member;
};
results in a memory leak when the following code is executed:
while (true) {
var test = new ValueType();
test.CharPtrMember = "Looooooooooooong string";
}
The set accessor allocates memory which is never freed outside of the set accessor.
At this time I see three options to solve this, listed in presumed increasing level of complexity:
- Disabling
char* to string marshalling for value type members
- Using
IDisposable
- Wrapping the unmanaged memory in a managed class that cleans up the memory when it gets finalized and having that class be an additional member of the value type.