import SwiftUI
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ContentView: View {
var body: some View {
VStack {
Text(testObjAutorelease()) // here is "Thread 1: EXC_BAD_ACCESS (code=1, address=...)" only in Release runtime
}
.padding()
}
}
func testObjAutorelease() -> String {
var t = TestStructObj()
fillObjAutorelease(&t)
return t.str
}
func fillObjAutorelease(_ t: AutoreleasingUnsafeMutablePointer<TestStructObj>) {
t.pointee.str = "fillObjAutorelease"
//print("test") -> uncomment leads to EXC_BAD_ACCESS
//print("\(t.pointee.str)") -> uncomment leads to EXC_BAD_ACCESS
//let i = t.pointee.str.count -> uncomment leads to EXC_BAD_ACCESS
}
I've faced this issue: with Release configuration app crashes with EXC_BAD_ACCESS if any of commented lines in fillObjAutorelease body are uncommented...
Double-check that you haven’t introduced a leak making this change. Still, UMP and AUMP should only differ when calling a setter on the Swift side, not the ObjC side, so I’m surprised you’re seeing different behavior. Running the AUMP version under Address Sanitizer may reveal where the object is getting prematurely released.
EDIT: the actual ObjC equivalent to UMP would use strong, not weak. But Swift may be handling that for you.