{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/3103","repository_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa","labels_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/3103/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/3103/comments","events_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/3103/events","html_url":"https://github.com/ReactiveCocoa/ReactiveCocoa/issues/3103","id":169148646,"number":3103,"title":"Signal deallocation timing","user":{"login":"yoching","id":3376690,"avatar_url":"https://avatars.githubusercontent.com/u/3376690?v=3","gravatar_id":"","url":"https://api.github.com/users/yoching","html_url":"https://github.com/yoching","followers_url":"https://api.github.com/users/yoching/followers","following_url":"https://api.github.com/users/yoching/following{/other_user}","gists_url":"https://api.github.com/users/yoching/gists{/gist_id}","starred_url":"https://api.github.com/users/yoching/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yoching/subscriptions","organizations_url":"https://api.github.com/users/yoching/orgs","repos_url":"https://api.github.com/users/yoching/repos","events_url":"https://api.github.com/users/yoching/events{/privacy}","received_events_url":"https://api.github.com/users/yoching/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-03T14:42:01Z","updated_at":"2016-08-04T00:16:58Z","closed_at":null,"body":"I have questions about the deallocation of `Signal`.\r\nI'm using RAC v4.2.2.\r\n\r\n1. When will a `Signal` be released?\r\n1. Are there any ways to handle signal deallocation like `deinit` closure of swift object?\r\n\r\nI wrote 2 cases that I don't understand the behavior of `Signal`.\r\nWould you tell me when the `Signal` be released in each case?\r\n\r\n\r\n**Case 1: using `pipe`**\r\n``` swift\r\nclass A {\r\n\r\n    let signal: Signal<Void, NoError>\r\n    let observer: Signal<Void, NoError>.Observer\r\n    \r\n    init() {\r\n        (signal, observer) = Signal<Void, NoError>.pipe()\r\n    }\r\n    \r\n    deinit {\r\n        print(\"A deinit\")\r\n        // observer.sendCompleted() // *\r\n    }\r\n}\r\n\r\nvar a: A?\r\na = A()\r\na = nil // prints \"A deinit\"\r\n// -> Will 'signal' be released too? Or, should I call 'observer.sendCompleted()'(*) in deinit closure in A?\r\n```\r\n\r\n\r\n\r\n**Case 2: using `SignalProducer`**\r\n``` swift\r\nclass B {\r\n    init() {\r\n        \r\n        SignalProducer<Void, NoError> { observer, disposable in\r\n            observer.sendNext()\r\n            }\r\n            .startWithSignal { signal, disposable in\r\n                // When will this 'signal' be released?\r\n        }\r\n    }\r\n    \r\n    deinit {\r\n        print(\"B deinit\")\r\n    }\r\n\r\n}\r\n\r\nvar b: B?\r\nb = B()\r\nb = nil // prints \"B deinit\"\r\n// Will signal created by producer be released? Or, should I call 'observer.sendCompleted()' somehow?\r\n```\r\n\r\nP.S. I'm learning and using RAC for about half a year. Thank you for the awesome library!😄"},"comment":{"url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/comments/237414527","html_url":"https://github.com/ReactiveCocoa/ReactiveCocoa/issues/3103#issuecomment-237414527","issue_url":"https://api.github.com/repos/ReactiveCocoa/ReactiveCocoa/issues/3103","id":237414527,"user":{"login":"andersio","id":11806295,"avatar_url":"https://avatars.githubusercontent.com/u/11806295?v=3","gravatar_id":"","url":"https://api.github.com/users/andersio","html_url":"https://github.com/andersio","followers_url":"https://api.github.com/users/andersio/followers","following_url":"https://api.github.com/users/andersio/following{/other_user}","gists_url":"https://api.github.com/users/andersio/gists{/gist_id}","starred_url":"https://api.github.com/users/andersio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andersio/subscriptions","organizations_url":"https://api.github.com/users/andersio/orgs","repos_url":"https://api.github.com/users/andersio/repos","events_url":"https://api.github.com/users/andersio/events{/privacy}","received_events_url":"https://api.github.com/users/andersio/received_events","type":"User","site_admin":false},"created_at":"2016-08-04T00:16:58Z","updated_at":"2016-08-04T00:16:58Z","body":"Case A: any references captured by the signal is released.\r\n\r\nCase B: The subscription would not stop. The produced signal stops only if its input observer receives a terminating event (which never happens in this case), or it is interrupted by the disposable passed to you in `startWithSignal`."}}
{"actor":{"display_login":"andersio"}}