The Leak is a Root Leak, In this image is being caused several times on the same line, but there is another below that is called single time and also produces a leak.
This is the call stack after calling the line of code stated before.
This is the class where the leak is located by Instruments:
class Item {
var id: String!
var name: String!
internal init(name: String) {
self.name = name
self.id = name
}
var description: String {
return "(\(id)) \(name)"
}
}
Leak is detected at line of computed variable description containing return "(\(id)) \(name)"
and it gets solved after changing description into:
var description: String {
return "(" + id + ") " + name
}
Update:
or
var description: String {
if let id = self.id as? String, let name = self.name as? String {
return "(\(id)) \(name)"
}
return "NO AVAILABLE DESCRIPTION"
}
The last one emits a "Conditional cast from 'String!' to String always succeeds".
So, even this looks like a hack.
Why is this causing a leak?