0
votes

I have a wrapper of AVPlayer called PGPlayer.So whenever I create an instance of PGPlayer like:

    PGPlayer *myPlayer = [PGPlayer new];

In the init() method of my PGPlayer class,I add an observer for keyPath "currentItem" like:

    [self addObserver:self forKeyPath:@"currentItem" options:NSKeyValueObservingOptionNew context:nil];

Now when this observer gets called,I add status observer like:

    [self.currentItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];

And when this observer gets called,I check for the status of currentItem and accordingly I add time observer and playerItem add observers like:

    if([keyPath isEqualToString:@"status"]){
    if(self.currentItem.status == AVPlayerItemStatusReadyToPlay){
        [self addPlayerItemTimeObserver];
        [self addItemEndObserverForPlayerItem];
        [self.delegate status:AVPlayerItemStatusReadyToPlay];
    }
}   

Now I select a video and present a view controller where I perform this task.
PROBLEM
Now the problem that I am facing is :if I make an instance of my PGPlayer and it sets the @"status" observer but that status observer has not called yet and before that I pop the view controller.In this case ,PGPlayer does not deallocate.But if I am on the same controller and status observer gets called and after that I pop the view controller,it works fine and my PGPlayer gets deallocated.Please help

1

1 Answers

0
votes

I'm having a similar (but opposite) problem where AVPlayerItem objects almost never get dealloced.

If I subclass AVPlayer, AVPlayerItem, and AVPlayerItemVideoOutput, and override their dealloc routines, I can see both AVPlayer and AVPlayerItemVideoOutput being dealloced, but AVPlayerItem (almost) never gets dealloced.