2011-02-10 3 views
4

AVCaptureSession을 사용하여 비디오를 처리하는 앱이 있습니다. 저는 메모리 누수가 전혀없고 모든 객체를 올바르게 처리하는 방법을 쓰고 싶습니다. How to properly release an AVCaptureSession - - 엄청난 도움이되었다 - [세션 stopRunning] 비동기이기 때문에, 당신은 단지 세션을 중지하고 유지 객체를 지속적으로 출시 할 수 없습니다이 게시물 이유applicationDidEnterBackground에서 AVCaptureSession을 정리하는 방법은 무엇입니까?

.

그래서 해결되었습니다.

// Releases the object - used for late session cleanup 
static void capture_cleanup(void* p) 
{ 
    CaptureScreenController* csc = (CaptureScreenController*)p; 
    [csc release]; // releases capture session if dealloc is called 
} 

// Stops the capture - this stops the capture, and upon stopping completion releases self. 
- (void)stopCapture { 
    // Retain self, it will be released in capture_cleanup. This is to ensure cleanup is done properly, 
    // without the object being released in the middle of it. 
    [self retain]; 

    // Stop the session 
    [session stopRunning]; 

    // Add cleanup code when dispatch queue end 
    dispatch_queue_t queue = dispatch_queue_create("capture_screen", NULL); 
    dispatch_set_context(queue, self); 
    dispatch_set_finalizer_f(queue, capture_cleanup); 
    [dataOutput setSampleBufferDelegate: self queue: queue]; 
    dispatch_release(queue); 
} 

가 지금은 전화 또는 홈 버튼을 누르면 같은 응용 프로그램의 중단을 지원하기 위해 오는 :이 코드입니다. 응용 프로그램이 백그라운드로 들어갈 경우 캡처를 중단하고 내 View Controller를 팝업하고 싶습니다.

applicationDidEnterBackground 컨텍스트에서이를 수행 할 수 없습니다. dealloc은 결코 호출되지 않고, 객체는 살아 남았고, 앱을 다시 열면 프레임이 자동으로 시작됩니다.

beginBackgroundTaskWithExpirationHandler를 사용했지만 아무 소용이 없습니다. 그것은별로 변하지 않았습니다.

제안 사항? 감사합니다.

답변

0

질문에 대한 답변이 없습니다. 그러나 나는 또한 thread you mentioned을 읽었으며 구현하려고합니다. 난 당신이 stopCapture 기능이 코드가 놀랍 :

// Add cleanup code when dispatch queue end 
dispatch_queue_t queue = dispatch_queue_create("capture_screen", NULL); 
dispatch_set_context(queue, self); 
dispatch_set_finalizer_f(queue, capture_cleanup); 
[dataOutput setSampleBufferDelegate: self queue: queue]; 
dispatch_release(queue); 

내가 그 코드가 세션 초기화의 일환으로 필요했다 생각합니다. 이 방법이 효과가 있습니까?

capture_cleanup 함수가 호출 되었습니까? 제 전화가 오지 않아서 그 이유를 알아 내려고합니다.

+0

안녕하세요,이 코드는 내 정리 코드에서 실제로 발견됩니다. 복사 - 붙여 넣기 오류 일 수 있지만 작동했습니다. capture_cleanup이 호출되었습니다. DataOutput 대기열을 바꾼 것으로 생각하고 정리를 완료하면 정리가 적절하게 호출됩니다. 하지만이 코드를 처음 게시 한 사람에게 물어볼 수도 있습니다 :) GL! –

+0

제 경우와 같은 문제는 capture_cleanup이 호출되지 않습니다. 어떤 생각? – polyclick

관련 문제