# New FString from char\*

**URL:** <https://forums.unrealengine.com/t/new-fstring-from-char/88520>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 26, 2017, 12:34am UTC](https://forums.unrealengine.com/t/new-fstring-from-char/88520 "2017-03-26T00:34:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zinglish](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zinglish](https://forums.unrealengine.com/u/Zinglish)\
**Post date:** [March 26, 2017, 12:34am UTC](https://forums.unrealengine.com/t/new-fstring-from-char/88520/1 "2017-03-26T00:34:58Z")

</div>

```auto

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?

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [March 26, 2017, 7:29am UTC](https://forums.unrealengine.com/t/new-fstring-from-char/88520/2 "2017-03-26T07:29:34Z")

</div>

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

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![Nico\_de\_Poel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nico\_de\_Poel](https://forums.unrealengine.com/u/Nico_de_Poel)\
**Post date:** [March 26, 2017, 1:27pm UTC](https://forums.unrealengine.com/t/new-fstring-from-char/88520/3 "2017-03-26T13:27:17Z")

</div>

_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()](https://docs.unrealengine.com/latest/INT/API/Runtime/Core/HAL/FMemory/Malloc/index.html)_ and _[FMemory::Free()](https://docs.unrealengine.com/latest/INT/API/Runtime/Core/HAL/FMemory/Free/index.html)_ instead, or the standard C++ _new]_ and _delete]_ operators.
