C++ and Objective C++ Gotachs
summary
Clang auto-fixes a void cast to an Objective‑C object by inserting __bridge, which lets ARC release the object prematurely and creates a use‑after‑free when C++ code runs on a new thread; the fix is to pass the object with __bridge_retained into C++ and return it with __bridge_transfer so ARC ownership moves safely across the boundary. For capturing C++ objects in Objective‑C blocks, replace naive weak references with a pattern using shared_from_this/weak_ptr* to create a weak capture, lock it to a strong pointer inside the block, and avoid races and crashes.
AI-written summary · about








