Swift: UnsafeMutablePointer.deinitialize fatal error with negative count when appending to array

前端 未结 2 1193
花落未央
花落未央 2021-02-05 04:56

The code below generates this error (appending to exporters):

fatal error: UnsafeMutablePointer.deinitialize with negative count

相关标签:
2条回答
  • 2021-02-05 05:32

    I have solved this type of issue like this way:

    DispatchQueue.global(qos: .background).sync {
            //your code 
        }
    
    0 讨论(0)
  • 2021-02-05 05:36

    I had a similar error, the issue was caused by multiple threads modifying the array at the same time. Wrapping the append calls in a serial dispatch queue solved it for me.

        let serialQueue = DispatchQueue(label: "myqueue")
    
        serialQueue.sync {
            exporters.append(exporter)
        }
    
    0 讨论(0)
提交回复
热议问题