IOS 5 instance of AVPlayerItem has been released

When I try to play a video from my iPhone (located in the documentsDirectory directory), I get the following error using iOS 5, while it works fine with iOS 4.3:

An instance of 0x168da0 of class AVPlayerItem was freed, and observers with key values ​​were still registered with it. Observational information has leaked and may even be erroneously tied to another object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here is the current observation information: (Context: 0x0, Property: 0x10b570> Context: 0x0, Property: 0x117ab0>

Here is a code excerpt:

MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[appDelegate.mediaManager loadVideo:[element valueForAttributeNamed:@"value"]]]; //create a NSNotificationCenter which call moviePlaybackComplete function when video playback finished [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController]; //display the moviePlayer view [self.view addSubview:moviePlayerController.view]; moviePlayerController.fullscreen = YES; [moviePlayerController play]; 
+6
source share
3 answers

EDIT:. After posting the answer below, I noticed that whenever the controller was redistributed, errors returned because the old controller was automatically freed up, even if I myself had created absolutely no notification handlers. Since errors come from code inside the MP framework, I would say that this seems to be an OS error.

I ran into the same issue with a storyboard-based iOS 5 project using ARC. The problem is using a temporary variable on the stack to access the movie controller - in my case, I assumed interacting with ARC, but this could be more fundamental. In any case, it seems that something is being freed / lost too early (for example, when a playback error occurs), and the log is filled with the description that you are describing.

Saving a reference to the movie controller in a property defined in the ownership class solved this in my case; i.e:

 @interface MyClass @property ( strong, nonatomic ) MPMoviePlayerViewController * movieController; @end @@implementation MyClass @synthesize movieController = _movieController; // ...then later, this: // // MPMoviePlayerController *moviePlayerController = [...]; // // ...becomes: self.movieController = [...]; 

If you use synthesized accessors for this property, then if you use manual or automatic reference counting, the generated setter method must correctly release the old video controller (if any) before setting up a new one.

As a footnote, if you (say) the dealloc / 'unreference' (set-to-nil) property is manually in the MPMoviePlayerPlaybackDidFinishNotification notification MPMoviePlayerPlaybackDidFinishNotification , then you will probably notice that errors are returned. So do not do this :-)

+13
source

Oh. You are observing a TekkPoint object from the SomethingElse object, and the SomethingElse object is the one that adds and removes observers, right? (What a normal way, everything is done, I'm just trying to clarify.)

It looks like your TekkPoint object is being freed, and SomethingElse that is watching it is still around. The SomethingElse dealloc method is not called because TekkPoint is freed, not SomethingElse.

If you plan to observe an object that may disappear before the observer disappears, you need to somehow notify the observers that they must remove their observers. Your TekkPoint may have a living property that will also be observed using SomethingElse, and when it gets a NO value, everyone who watches TekkPoint will remove themselves as an observer.

0
source

I had the same error before and just remove the observer when the view goes away, clear the leak.

Placed

 [[NSNotificationCenter defaultCenter] removeObserver:self]; 

in willWillDisappear or dealloc

-5
source

Source: https://habr.com/ru/post/900929/


All Articles