2012-02-23 3 views
1

변수가 좀비 인 지 확인하고 싶습니다. &이 아니라면, 실제로 존재한다면 슈퍼 레이어에서 제거해야하는 곳이 있는데, 이미 제거되었지만 좀비 인 것 같습니다. 이 시점에서 충돌합니다. 런타임에 변수가 좀비인지 아닌지 확인하려면 어떻게해야합니까?변수가 좀비이거나 아닌 경우?

if (avPlayerLayer) { 
     [avPlayerLayer removeFromSuperlayer]; 
} 

나는 그것을 만들려면이 코드를 가지고 :

if (!avPlayer) { 
     avPlayer = [[AVPlayer alloc] initWithURL:movieURL]; 
    } else { 
     [avPlayer replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:movieURL]]; 
     avPlayer.rate = 0.0f; 
    } 
} 
avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer]; 

내가 대신이 같은 일을해야?

if (!avPlayer) { 
     avPlayer = [[AVPlayer alloc] initWithURL:movieURL]; 
    } else { 
     avPlayer = nil; 
     avPlayer = [[AVPlayer alloc] initWithURL:movieURL]; 
     avPlayer.rate = 0.0f; 
    } 
} 
avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer]; 

어떤 도움? 미리 감사드립니다!

+0

처음에는 좀비가 없어야합니다. 그런 상황이 있어야만한다면 ARC와 약점을 사용하십시오. –

+0

리처드, 고맙습니다.하지만 지금 전체 프로젝트를 변경하고 싶지 않습니다. 다음 번엔 고려해 보겠습니다. – Oscar

답변

1

대신 변수를 nil로 설정 한 다음 nil을 확인하십시오. 당신이 당신의 첫 번째 구현에서 간단한 불일치를 보인다

+1

슈퍼 레이어가 제거 될 때 문제가 발생한다고 생각합니다. –

+0

당신은 바로 오스카였습니다. 나는 avPlayerLayer = nil을 넣었습니다. after [avPlayerLayer removeFromSuperlayer]; & 그것은 다시 추락하지 않았다 – Oscar

0

---

if (!avPlayer) { 

    // This sets avPlayer to a retained object reference (retainCount==1) 
    avPlayer = [[AVPlayer alloc] initWithURL:movieURL]; 
} else { 
    // This sets avPlayer to an autoReleased object reference 
    // which will die as soon as the memory pool is drained next. 
    // You should have retained it before setting, and your problem will be gone. 
    [avPlayer replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:movieURL]]; 
    avPlayer.rate = 0.0f; 
} 

내가 사용합니다 :

[avPlayer replaceCurrentItemWithPlayerItem:[[AVPlayerItem playerItemWithURL:movieURL] retain]]; 

BTW, 당신은에서 객체의 "zombieness"를 확인할 수 없습니다 왜냐하면 좀비 메커니즘은 클라이언트 시스템에서 설정할 수없는 일부 시스템 구성 (환경 변수 등)에 의존하기 때문입니다. 이것은 디버그 전용 도구이며 적절한 개발 기술이 아닙니다. 좀비는 프로그램의 버그입니다. 좀비는 메모리 관련 버그를 찾아 제거하는 데 도움을주기 위해 만들어졌습니다. 그렇지 않으면 추적하기가 매우 어려웠습니다.

+0

좀비에 대한 설명에 대한 모티 감사합니다. 알아 둘만한 – Oscar

관련 문제