Swinject:使用弱范围泄漏对象

时间:2017-05-23 13:43:39

标签: ios swift dependency-injection swinject

我在我的快速项目中使用Swinject进行DI。我认为使用弱对象范围会导致泄漏。

我有这个虚拟对象

protocol DevTestProtocol: class {}
class DevTest: DevTestProtocol {}

注册如下(我正在使用程序集)

container.register(DevTestProtocol.self) { _ in
    return DevTest()
}
.inObjectScope(.weak)

出于测试目的,我在我的app delegate

中添加了一个属性
var devTest: DevTestProtocol?

并在applicationDidFinishLaunchingWithOptions中解析对象然后忘掉它

self.devTest = DI.resolve(DevTestProtocol.self)!
self.devTest = nil

DevTest实例现在应该消失了吗? 因为事实并非如此。它仍然在调试存储器图中显示为泄漏。 see screenshot

我猜这不是预期的行为?我错过了什么吗? 它看起来像是一个错误,它搞砸了我的整个设置。 我们能做些什么呢? GitHub issue

1 个答案:

答案 0 :(得分:0)

没有内存泄漏,它只是Xcode 8内存分析工具中的一个错误。请参阅GitHub issues tracker

讨论

enter image description here