{"action":"created","issue":{"url":"https://api.github.com/repos/AliSoftware/Dip/issues/23","labels_url":"https://api.github.com/repos/AliSoftware/Dip/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/AliSoftware/Dip/issues/23/comments","events_url":"https://api.github.com/repos/AliSoftware/Dip/issues/23/events","html_url":"https://github.com/AliSoftware/Dip/issues/23","id":119793895,"number":23,"title":"Investigate possible retain cycles passing container in factory/resolveDependenciesBlock","user":{"login":"ilyapuchka","id":1488293,"avatar_url":"https://avatars.githubusercontent.com/u/1488293?v=3","gravatar_id":"","url":"https://api.github.com/users/ilyapuchka","html_url":"https://github.com/ilyapuchka","followers_url":"https://api.github.com/users/ilyapuchka/followers","following_url":"https://api.github.com/users/ilyapuchka/following{/other_user}","gists_url":"https://api.github.com/users/ilyapuchka/gists{/gist_id}","starred_url":"https://api.github.com/users/ilyapuchka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilyapuchka/subscriptions","organizations_url":"https://api.github.com/users/ilyapuchka/orgs","repos_url":"https://api.github.com/users/ilyapuchka/repos","events_url":"https://api.github.com/users/ilyapuchka/events{/privacy}","received_events_url":"https://api.github.com/users/ilyapuchka/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-01T19:52:47Z","updated_at":"2015-12-01T20:42:34Z","closed_at":null,"body":"As @AliSoftware pointed out in #22 discussion there could be some retain cycles between container and definitions. Will investigate this possibility in this issue.\r\n\r\n----\r\n\r\nDiscussion from #22 :\r\n\r\n_AliSoftware:_\r\n> Not related to this PR I know, but now that I read that again I'm wondering: shouldn't we use [unowned container] (or at least [weak container]) here? It seems to me that container strongly reference resolveDependenciesBlock which itself strongly references container, hence a strong reference cycle, right?\r\n\r\n_ilyapuchka:_\r\n> I don't think so, cause here we don't capture container from outer context, we pass it as an argument at runtime. So the reference should be released as soon as block returns. I suppose...\r\n\r\n> Speaking of unowned I tried to use factory block without `[unowned container]` it (like in line 93) and it still looks like there is no retain cycle... I test it by having a strong reference to container and a weak reference. When I release a strong reference weak also is being released. That would not happen in retain cycle... but if I think of it there should be one if there is no `[unowned container]` or `[weak container]`, cause container holds definitions and they hold their factories... Maybe it's just too late at night to think about that :sleepy:  :night_with_stars:\r\n\r\n_AliSoftware:_\r\n> I don't think so, cause here we don't capture container from outer context, we pass it as an argument at runtime. So the reference should be released as soon as block returns.\r\nDon't we? I mean, container captures resolveDependenciesBlock right? So unless that block don't use the container argument in the closure, this container is captured automatically by the closure and not \"released as soon as the block returns\" (as the resolveDependenciesBlock will still be captured and kept as a property in the container). So this captured container will only be released when the block itself is released (set back to nil).\r\n\r\n> (If the block were not stored as a strong property by the container but used right away, we would be able to mark it @noescape, which is not the case here)"},"comment":{"url":"https://api.github.com/repos/AliSoftware/Dip/issues/comments/161089477","html_url":"https://github.com/AliSoftware/Dip/issues/23#issuecomment-161089477","issue_url":"https://api.github.com/repos/AliSoftware/Dip/issues/23","id":161089477,"user":{"login":"ilyapuchka","id":1488293,"avatar_url":"https://avatars.githubusercontent.com/u/1488293?v=3","gravatar_id":"","url":"https://api.github.com/users/ilyapuchka","html_url":"https://github.com/ilyapuchka","followers_url":"https://api.github.com/users/ilyapuchka/followers","following_url":"https://api.github.com/users/ilyapuchka/following{/other_user}","gists_url":"https://api.github.com/users/ilyapuchka/gists{/gist_id}","starred_url":"https://api.github.com/users/ilyapuchka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilyapuchka/subscriptions","organizations_url":"https://api.github.com/users/ilyapuchka/orgs","repos_url":"https://api.github.com/users/ilyapuchka/repos","events_url":"https://api.github.com/users/ilyapuchka/events{/privacy}","received_events_url":"https://api.github.com/users/ilyapuchka/received_events","type":"User","site_admin":false},"created_at":"2015-12-01T20:42:34Z","updated_at":"2015-12-01T20:42:34Z","body":"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.\r\n\r\nHere is a gist - https://gist.github.com/ilyapuchka/8d0690101f23c6d09225\r\nThere A class stands for Dip definitions, B stands for container.\r\n\r\nAm I missing something?"}}