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
Investigate possible retain cycles passing container in factory/resolveDependenciesBlock #23
Comments
I'm still quite confident that passing container as an argument in runtime is ok. Otherwise we would need to wrap each call to { [unowned self] in
definition.resolveDependenciesBlock?(self, resolvedInstance)
}() The case with capturing container in factory block is more likely will lead to retain cycle, so I will write some unit tests to check that or try out some sample code. |
I tried it with a simple playground code. No retain cycles at all, even if capturing container strongly in factory block. That I can not explain. Here is a gist - https://gist.github.com/ilyapuchka/8d0690101f23c6d09225 Am I missing something? |
Mmhh not sure I understand it either. what sorcery is this?! |
At one moment I thought it could be that array is a struct and it change the rules somehow (but still there should be strong references to each of it's items anyway) but I tried with NSArray - the same. |
Just asked around on Slack will see if someone has clearer thoughts than we do! |
Maybe swift is smart enough to solve such kind of cases. Cause there are something happening under the hood that we don't know, like this - https://twitter.com/jckarter/status/655031895122579456 |
Everything is clear now - https://twitter.com/jckarter/status/671812668005584896 func addA() -> A {
let a = A(factory: {
print("factory \(self)")
})
b.array.append(a)
return a
} then it will create a retain cycle. |
Ahhh got it. Tricky one still. |
Yep, though I messed up with variables and used |
As @AliSoftware pointed out in #22 discussion there could be some retain cycles between container and definitions. Will investigate this possibility in this issue.
Discussion from #22 :
AliSoftware:
ilyapuchka:
AliSoftware:
The text was updated successfully, but these errors were encountered: