Hi!
I am developing an app (in XCode Version 11.2 and Swift 4.2) in which I fill in a LinkedList and after working with it, removing the elements that compose it produces the Thread 1 error: EXC_BAD_ACCESS (code = 2, address = 0x16d0f3ff0). The error occurs even without working with the items in the list, simply by adding them and trying to eliminate them the error already occurs. The tests I am doing with an iPhone with IOS version 11.4.1
The method that eliminates the elements of the LinkedList is removeAll.
The error occurs in the first line:
public func removeAll() {
self.head = nil //Thread 1: EXC_BAD_ACCESS (code=2, address=0x16d0f3ff0)
self.tail = nil
self.count = 0
} // removeAll
the definition of the variables 'head', 'tail', 'count':
private var head: Node<T>?
private var tail: Node<T>?
public private(set) var count: Int = 0
And the type Node<T>:
public class Node<T> {
var value: T
var next: Node<T>?
weak var previous: Node<T>?
init(value: T) {
self.value = value
} // init
} // Node
With the debugger I see that the error occurs when assigning the value nil to self.head (in removeAll()). Just before self.head has correct values, it becomes nil and the error is skipped before reaching the next instruction.
In the Debug Navigator, in the stackTrace the last 2 functions where the error is seen:
libobjc.A.dylib`_object_remove_assocations:
0x180d11eec <+0>: sub sp, sp, #0x70 ; =0x70
-> 0x180d11ef0 <+4>: stp x26, x25, [sp, #0x20] //Thread 1 error: EXC_BAD_ACCESS (code = 2, address = 0x16d0f3ff0)
0x180d11ef4 <+8>: stp x24, x23, [sp, #0x30]
libswiftCore.dylib`_swift_release_:
0x104e18d1c <+180>: bl 0x104e1a37c ; bool swift::RefCounts<swift::SideTableRefCountBits>::doDecrement<(swift::PerformDeinit)1>(unsigned int)
-> 0x104e18d20 <+184>: ldp x29, x30, [sp], #0x10. //Thread 1 error: EXC_BAD_ACCESS (code = 2, address = 0x16d0f3ff0)
0x104e18d24 <+188>: ret
Does someone have idea how to resolve it?
Thanks!