New FString from char*



char* MyAllocData = (char*)malloc(MyLen) + 1;
FString MyString(ANSI_TO_TCHAR(MyAllocData));


Would this cause a memory leak when MyString goes out of scope?

I attempted to free() my malloc() but met angry crashes from UE4’s object manager and assumed that the FString had seized ownership of the pointer. Is this the right assumption?

Anything not marked as an UPROPERTY() will not be cleaned by GC properly.

ANSI_TO_TCHAR will create a (converted) copy of the original ANSI string, so FString taking ownership of the char-pointer should not be the issue here. I’m not sure how much UE4 likes you using regular old malloc() and free() though, since the engine has its own memory allocators and platform abstractions that it injects at various points and expects you to use. You could try using FMemory::Malloc() and FMemory::Free() instead, or the standard C++ new] and delete] operators.