I'm using Swinject for DI in my swift project. I think using weak object scope is leading to leaks.
I have this dummy object
protocol DevTestProtocol: class {}
class DevTest: DevTestProtocol {}
which is registered like follows (I'm using an assembly)
container.register(DevTestProtocol.self) { _ in
return DevTest()
}
.inObjectScope(.weak)
For testing purposes I added a property in my app delegate
var devTest: DevTestProtocol?
and in applicationDidFinishLaunchingWithOptions I resolve the object then forget about it
self.devTest = DI.resolve(DevTestProtocol.self)!
self.devTest = nil
Is the DevTest instance supposed to be gone by now? Because it's not. It still shows in the debug memory graph as a leak. see screenshot
I guess this isn't expected behaviour? Am I missing something? It looks like a bug to me and it's messing up my whole setup. What can we do about this? GitHub issue
There is no memory leak, it's just a bug in Xcode 8 memory profiling instruments. See discussing at GitHub issues tracker