{"action":"created","issue":{"url":"https://api.github.com/repos/rFlex/SCRecorder/issues/214","labels_url":"https://api.github.com/repos/rFlex/SCRecorder/issues/214/labels{/name}","comments_url":"https://api.github.com/repos/rFlex/SCRecorder/issues/214/comments","events_url":"https://api.github.com/repos/rFlex/SCRecorder/issues/214/events","html_url":"https://github.com/rFlex/SCRecorder/issues/214","id":107405935,"number":214,"title":"Memory leak on prepareCamera","user":{"login":"loretoparisi","id":163333,"avatar_url":"https://avatars.githubusercontent.com/u/163333?v=3","gravatar_id":"","url":"https://api.github.com/users/loretoparisi","html_url":"https://github.com/loretoparisi","followers_url":"https://api.github.com/users/loretoparisi/followers","following_url":"https://api.github.com/users/loretoparisi/following{/other_user}","gists_url":"https://api.github.com/users/loretoparisi/gists{/gist_id}","starred_url":"https://api.github.com/users/loretoparisi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loretoparisi/subscriptions","organizations_url":"https://api.github.com/users/loretoparisi/orgs","repos_url":"https://api.github.com/users/loretoparisi/repos","events_url":"https://api.github.com/users/loretoparisi/events{/privacy}","received_events_url":"https://api.github.com/users/loretoparisi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-09-20T17:31:25Z","updated_at":"2015-10-09T20:44:55Z","closed_at":null,"body":"I'm trying to restart automatically a new ```SCRecordSession``` as soon the previous session is completed (getting the ```didCompleteRecordSession``` delegate). It seems that this causes a memory leak:\r\n\r\nThe code is like:\r\n\r\n```Objective-c\r\n- (void)recorder:(SCRecorder *)recorder didCompleteRecordSession:(SCRecordSession *)recordSession {\r\n    \r\n    [self captureVideoBuffer:nil]; // to get last capture\r\n    _recorder.recordSession = nil;\r\n    [self prepareCamera];  /// this is causing the leak\r\n    [self updateTimeRecordedLabel];\r\n    [_recorder record];\r\n\r\n}\r\n```\r\n\r\nThe leak seamed (see latest comment) to be caused by ```prepareCamera``` and so due to the init of the new ```SCRecordSession```:\r\n\r\n```Objective-c\r\nif (_recorder.recordSession == nil) {\r\n        SCRecordSession *session = [SCRecordSession recordSession];\r\n        _recorder.recordSession = session;\r\n    }\r\n```\r\n\r\nI need the prepareCamera, otherwise I'm not getting the last video buffer updated:\r\n\r\n```Objective-c\r\nUIImage *__lastImage = [_recorder snapshotOfLastAppendedVideoBuffer];\r\n```\r\n\r\nLooking at the last implementation, I have also tried to reference the passed ```SCRecordSession``` object and clean it up like:\r\n\r\n```Objective-c\r\n- (void)recorder:(SCRecorder *)recorder didCompleteRecordSession:(SCRecordSession *)recordSession {\r\n    //[self saveAndShowSession:recordSession];\r\n    \r\n    [self captureVideoBuffer:nil];\r\n    \r\n    _recordSession = recordSession;\r\n    if (_recordSession != nil) {\r\n        _recorder.recordSession = nil;\r\n        // If the recordSession was saved, we don't want to completely destroy it\r\n        if ([[SCRecordSessionManager sharedInstance] isSaved:recordSession]) {\r\n            [recordSession endRecordSegment:nil];\r\n        } else {\r\n            [recordSession cancelSession:nil];\r\n        }\r\n    }\r\n    \r\n    [self prepareCamera];\r\n    [self updateTimeRecordedLabel];\r\n    \r\n    [_recorder record];\r\n\r\n}\r\n```\r\n\r\nBut it keeps leaking. Maybe I'm wrong on how to initialize a new ```SCRecordSession``` automatically.\r\n\r\n    "},"comment":{"url":"https://api.github.com/repos/rFlex/SCRecorder/issues/comments/146981941","html_url":"https://github.com/rFlex/SCRecorder/issues/214#issuecomment-146981941","issue_url":"https://api.github.com/repos/rFlex/SCRecorder/issues/214","id":146981941,"user":{"login":"loretoparisi","id":163333,"avatar_url":"https://avatars.githubusercontent.com/u/163333?v=3","gravatar_id":"","url":"https://api.github.com/users/loretoparisi","html_url":"https://github.com/loretoparisi","followers_url":"https://api.github.com/users/loretoparisi/followers","following_url":"https://api.github.com/users/loretoparisi/following{/other_user}","gists_url":"https://api.github.com/users/loretoparisi/gists{/gist_id}","starred_url":"https://api.github.com/users/loretoparisi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loretoparisi/subscriptions","organizations_url":"https://api.github.com/users/loretoparisi/orgs","repos_url":"https://api.github.com/users/loretoparisi/repos","events_url":"https://api.github.com/users/loretoparisi/events{/privacy}","received_events_url":"https://api.github.com/users/loretoparisi/received_events","type":"User","site_admin":false},"created_at":"2015-10-09T20:44:55Z","updated_at":"2015-10-09T20:44:55Z","body":"@mjgaylord that's a super finding! I will check it with the latest beta. Back with some results."}}