# iOS crash on std::string allocation

**URL:** <https://forums.unrealengine.com/t/ios-crash-on-std-string-allocation/666202>\
**Category:** Mobile\
**Tags:** unreal-engine, iOS, UE4, question\
**Created:** [October 10, 2022, 9:03am UTC](https://forums.unrealengine.com/t/ios-crash-on-std-string-allocation/666202 "2022-10-10T09:03:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_e10ac3b2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e10ac3b2](https://forums.unrealengine.com/u/anonymous_user_e10ac3b2)\
**Post date:** [October 10, 2022, 9:03am UTC](https://forums.unrealengine.com/t/ios-crash-on-std-string-allocation/666202/1 "2022-10-10T09:03:28Z")

</div>

I use a dynamic native library, then crashes about std::string only on UE4, it look like [c++ - iphone XS, " std::\_\_1::basic\_string, std::\_\_1::allocator \>::~basic\_string()" Crash - Stack Overflow](https://stackoverflow.com/questions/56895693/iphone-xs-std-1basic-string-std-1allocator-basic-string-cra)

I guess it’s about the crash caused by the incompatibility between libstdc++and libc++.

it’s crashing in this function base::SplitstringusingSubstr, this chromium base function, this is no problem, and it is ok on Unity.

Thread 17 Crashed:  
0 libsystem\_kernel.dylib 0x1caeaa200 \_\_pthread\_kill + 8  
1 libsystem\_pthread.dylib 0x1db0e71ac pthread\_kill + 268  
2 libsystem\_c.dylib 0x195ca1ca0 abort + 180  
3 libsystem\_malloc.dylib 0x19c9c6548 malloc\_vreport + 552  
4 libsystem\_malloc.dylib 0x19c9c6720 malloc\_report + 64  
5 libsystem\_malloc.dylib 0x19c9aa47c free + 300  
6 libc++.1.dylib 0x19cb6671c std::\_\_1::basic\_string\<char, std::\_\_1::char\_traits, std::\_\_1::allocator \>::~basic\_string() + 36  
7 TTNetworkManager 0x10d5eefc8 0x10d4ac000 + 1322952

I’m now trying to address the problem. Any advice would be great.

Thank you.

---

<div class="post-metadata">

**Author:** ![rainb00ts](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rainb00ts](https://forums.unrealengine.com/u/rainb00ts)\
**Post date:** [October 11, 2022, 11:25pm UTC](https://forums.unrealengine.com/t/ios-crash-on-std-string-allocation/666202/2 "2022-10-11T23:25:22Z")

</div>

Also experiencing this, can you confirm if this on iOS 16?

I believe there’s an issue linking the libc++ library on iOS 16 and UE 4/5

edit: just seeing this goes way back… it looks like the suggested fix here no longer applies beyond iPhone X (yikes!):

> [@Ios crash on launch arm64 distribution build](https://forums.unrealengine.com/t/ios-crash-on-launch-arm64-distribution-build/356199/14):
>
> We ran into this problem too. Did anybody find a fix that will work with the latest iphones?

---

<div class="post-metadata">

**Author:** ![zhaojunmeng](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zhaojunmeng](https://forums.unrealengine.com/u/zhaojunmeng)\
**Post date:** [February 28, 2025, 3:05am UTC](https://forums.unrealengine.com/t/ios-crash-on-std-string-allocation/666202/3 "2025-02-28T03:05:27Z")

</div>

iOS16 has a bug that operator new/delete override will fail, see:

> **[Operator new/delete override only … | Apple Developer Forums](https://developer.apple.com/forums/thread/774805)**

To figure out why the crash happens, you need to check whether the std::string’s memory allocation and free occur in the same way.

We found a case that std::string’s allocation is in the libc++.1.dylib, and the destructor is inlined in the main executable which use UE’s allocator. Because os iOS16 operator new/delete will fail, so the allocation in the libc++.1.dylib will not use UE’s allocator, so the mismatch happens, and the app crashed.

The solution could be:

- replace the usage of std::string to FString
- Use Ansi or Binned1 allocator on iOS. Allocator Binned1 checks PtrIsOSMalloc() and will not free memory allocated by OS.
