swift报错Fatal error: UnsafeMutablePointer.deinitialize with negative count

这个问题是由多个线程同时修改数组引起的,是个线程安全问题。

解决办法:

1.修改数组在同步队列中

let queue = DispatchQueue(label:myqueue)

queue.sync {

myArray.append(...)

}

2.在数组修改前后加锁

objc_sync_enter(self)

myArray.append(...)

objc_sync_exit(self)


此外,不加锁也可能造成以下问题引起闪退

1、malloc: Heap corruption detected, free list is damaged at 0x600000fb42d0

2、Thread 83: EXC_BAD_ACCESS (code=1, address=0x3eadddea39a0)

你可能感兴趣的:(swift报错Fatal error: UnsafeMutablePointer.deinitialize with negative count)