0

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

Alexis
  • 16,629
  • 17
  • 62
  • 107

1 Answers1

0

There is no memory leak, it's just a bug in Xcode 8 memory profiling instruments. See discussing at GitHub issues tracker

enter image description here

Ihar Katkavets
  • 1,510
  • 14
  • 25