I am detecting a memory leak when using string interpolation with Swift. Using the "Leaks" instrument, it shows the leaked object as a "Malloc 32 bytes", but no responsible library or frame. This seems to be caused by using optionals in string interpolation.
class MySwiftObject
{
let boundHost:String?
let port:UInt16
init(boundHost: String?, port: UInt16)
{
if boundHost {
self.boundHost = boundHost!
}
self.port = port
// leaks
println("Server created with host: \(self.boundHost) and port: \(self.port).")
}
}
However, if I replace the string interpolation with simply building a String by appending pieces, no memory leak.
// does not leak
var message = "Server created with host: "
if self.boundHost
{
message += self.boundHost!
}
else
{
message += "*"
}
message += " and port: \(self.port)"
println(message)
Is there something I am doing wrong above, or just a Swift bug?