Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Удержание аргумента при резольве объектов #214

Closed
NSSimpleApps opened this issue Nov 7, 2018 · 4 comments

Comments

@NSSimpleApps
Copy link

NSSimpleApps commented Nov 7, 2018

class A {
    deinit {
        print("DEINIT A") // НЕ БУДЕТ ВЫЗВАН ДЛЯ swift4.2
    }
}
class B {
    weak var a: A?
    init(a: A) {
        self.a = a
    }
    deinit {
        print("DEINIT B")
    }
}
import Dip // 7.0
let container = DependencyContainer()    
let tag = "my_tag"
container.register(.unique, tag: tag,
factory: { arg in
     B(a: arg)
})
do {
     let a0 = A()
     let b0: B = try container.resolve(tag: tag, arguments: a0)
     print(a0, b0)
} catch {
     print(error)
}

При создании такой фабрики объектов аргумент a0 удерживается и не высвобождается при компиляции на Xcode10 swift4.2
Такой же код на Xcode9.4.1 swift4.1 не вызывает удержания объекта a0.

@aka-toxa
Copy link

lol i dont think that anyone from here knows Russian language

@ilyapuchka
Copy link
Collaborator

@NSSimpleApps thanks for bringing this up. This turns out to be a swift bug, that should have been fixed https://bugs.swift.org/browse/SR-8878
Unfortunately I don't think there is currently a workaround for that as Dip automatically insects registered types using Mirror type to perform auto injection. Unless we consider #212 .

@ilyapuchka
Copy link
Collaborator

ilyapuchka commented Nov 19, 2018

@NSSimpleApps you can now configure container to not attempt to auto inject properties if you don't use this feature. Unfortunately the issue will still be present if you use auto injection.

@ilyapuchka
Copy link
Collaborator

The fix is now released with 7.0.1. version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants