I am creating an object where I call it to run a function in a Boolean loop controlled by a button. Once the object is created I call two functions of it so that I may get a return value and pass them to the next function. Once the loop completes the object is still referenced so that it is not set to zero by ARC and thus I created a memory leak. I am trying to wrap my head around using the weak reference type but when I attempt the object continues to be referenced. I am going to paste the code that leaks without any alterations to the variable types or creating an optional operators so that you can see where I started from.
self.buttonpress = true
DispatchQueue.global().async{
while buttonpress == true{
let varfind = find()
let b = varfind.build()
let yes = varfind.isInside(index: b,xaxis: locationViewModel.userXaxis, yaxis: locationViewModel.userYaxis)
self.final = String(Int(locationViewModel.userZaxis)-yes)
}
}
The question is, how do i have what is inside the while loop execute and dereference the object and its pointers so that it does not increasingly take up memory and crash using weak variable types?
I understand that I need to use let varfind : find? = find(), then add a deinit inside the find class in order to set everything to nil however, I think there is a misunderstanding when it comes to settings the params inside var yes to nil as index for example is a [String] so it can only accept an empty array?

