{"action":"created","issue":{"url":"https://api.github.com/repos/eface2face/cordova-plugin-iosrtc/issues/160","repository_url":"https://api.github.com/repos/eface2face/cordova-plugin-iosrtc","labels_url":"https://api.github.com/repos/eface2face/cordova-plugin-iosrtc/issues/160/labels{/name}","comments_url":"https://api.github.com/repos/eface2face/cordova-plugin-iosrtc/issues/160/comments","events_url":"https://api.github.com/repos/eface2face/cordova-plugin-iosrtc/issues/160/events","html_url":"https://github.com/eface2face/cordova-plugin-iosrtc/pull/160","id":148229262,"number":160,"title":"Use closure syntax for weak and unowned vars.","user":{"login":"oNaiPs","id":374130,"avatar_url":"https://avatars.githubusercontent.com/u/374130?v=3","gravatar_id":"","url":"https://api.github.com/users/oNaiPs","html_url":"https://github.com/oNaiPs","followers_url":"https://api.github.com/users/oNaiPs/followers","following_url":"https://api.github.com/users/oNaiPs/following{/other_user}","gists_url":"https://api.github.com/users/oNaiPs/gists{/gist_id}","starred_url":"https://api.github.com/users/oNaiPs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oNaiPs/subscriptions","organizations_url":"https://api.github.com/users/oNaiPs/orgs","repos_url":"https://api.github.com/users/oNaiPs/repos","events_url":"https://api.github.com/users/oNaiPs/events{/privacy}","received_events_url":"https://api.github.com/users/oNaiPs/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-14T02:00:08Z","updated_at":"2016-04-14T10:50:04Z","closed_at":"2016-04-14T08:09:02Z","pull_request":{"url":"https://api.github.com/repos/eface2face/cordova-plugin-iosrtc/pulls/160","html_url":"https://github.com/eface2face/cordova-plugin-iosrtc/pull/160","diff_url":"https://github.com/eface2face/cordova-plugin-iosrtc/pull/160.diff","patch_url":"https://github.com/eface2face/cordova-plugin-iosrtc/pull/160.patch"},"body":"This PR uses closure syntax to define the weak/unowned variables or self, and fixes strong reference loop bugs in setLocalDescription and setRemoteDescription.\r\nWithout this fix, calling RTCPeerConnection.close() on javascript will not correctly deallocate all underlying native objects."},"comment":{"url":"https://api.github.com/repos/eface2face/cordova-plugin-iosrtc/issues/comments/209876842","html_url":"https://github.com/eface2face/cordova-plugin-iosrtc/pull/160#issuecomment-209876842","issue_url":"https://api.github.com/repos/eface2face/cordova-plugin-iosrtc/issues/160","id":209876842,"user":{"login":"ibc","id":16191,"avatar_url":"https://avatars.githubusercontent.com/u/16191?v=3","gravatar_id":"","url":"https://api.github.com/users/ibc","html_url":"https://github.com/ibc","followers_url":"https://api.github.com/users/ibc/followers","following_url":"https://api.github.com/users/ibc/following{/other_user}","gists_url":"https://api.github.com/users/ibc/gists{/gist_id}","starred_url":"https://api.github.com/users/ibc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibc/subscriptions","organizations_url":"https://api.github.com/users/ibc/orgs","repos_url":"https://api.github.com/users/ibc/repos","events_url":"https://api.github.com/users/ibc/events{/privacy}","received_events_url":"https://api.github.com/users/ibc/received_events","type":"User","site_admin":false},"created_at":"2016-04-14T10:50:04Z","updated_at":"2016-04-14T10:50:04Z","body":"It does not crash as follows:\r\n\r\n```switf\r\nfunc RTCPeerConnection_close(command: CDVInvokedUrlCommand) {\r\n\t\tNSLog(\"iosrtcPlugin#RTCPeerConnection_close()\")\r\n\r\n\t\tlet pcId = command.argumentAtIndex(0) as! Int\r\n\t\tlet pluginRTCPeerConnection = self.pluginRTCPeerConnections[pcId]\r\n\r\n\t\tif pluginRTCPeerConnection == nil {\r\n\t\t\tNSLog(\"iosrtcPlugin#RTCPeerConnection_close() | ERROR: pluginRTCPeerConnection with pcId=%@ does not exist\", String(pcId))\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tdispatch_async(self.queue) {\r\n\t\t\tpluginRTCPeerConnection!.close()\r\n\t\t}\r\n\r\n\t\t// Remove the pluginRTCPeerConnection from the dictionary.\r\n\t\tself.pluginRTCPeerConnections[pcId] = nil\r\n\t}\r\n```\r\n\r\nI've also tried passing `[weak pluginRTCPeerConnection] in` to `dispatch_async()` but it crashes as well, so I'm worried whether the native object is not properly deallocated.\r\n\r\nIf so, would this work?\r\n\r\n```swift\r\n\t\tdispatch_async(self.queue) {\r\n\t\t\tpluginRTCPeerConnection!.close()\r\n\t\t\tpluginRTCPeerConnection = nil\r\n\t\t}\r\n```"}}