How can I check when an instance of MPMoviePlayerController
is deallocated? Note I already have NSZombieEnabled set to YES and checked.
The code in question works great under some circumstances in my app. In another, when the view with the moviePlayer controls is expanded, the MPMoviePlayerDidEnterFullscreenNotification
callback method is executed and shortly after the screen goes black and the app from user viewpoint freezes. (The difference is this one has an extra viewController on the navigation stack). It does not crash the app. It is still running but can not return back to a usable UI.
In the debugger, I check the last known time when the instance was "alive" to get its address, to check and find it is deallocated:
2012-10-01 18:35:46.032 MyApp[930:907] -[MyMoviePlayerViewController moviePlayerDidEnterFullscreenNotification:](203): : moviePlayer = <MPMoviePlayerController: 0x1dba9420> loadState = 3
2012-10-01 18:36:05.280 MyApp[930:907] [MPAVController] Autoplay: Enabling autoplay
Black screen occurs here, so I check the debugger:
(lldb) po 0x1dba9420
2012-10-01 18:37:38.656 MyApp[930:907] *** -[MPMoviePlayerController respondsToSelector:]: message sent to deallocated instance 0x1dba9420
(int) $0 = 498766880 [no Objective-C description available]
If I check other known instance of other classes, they are alive and well as expected:
(lldb) po 0x1da12110
(int) $1 = 497099024 <MyDetailViewControllerWithTableView: 0x1da12110>
(lldb) po 0x1da1af70
(int) $2 = 497135472 <MyMasterTableViewController: 0x1da1af70>
(lldb) po 0x1da19be0
(int) $3 = 497130464 <NSFetchedResultsController: 0x1da19be0>
So, to reiterate, how does one check when and by what an instance gets deallocated or destroyed? Is there an Instruments type that can be used. Allocations shows that instances was allocated and now not alive....
I suppose I can do a fine step by step trace but that is tedious... Would be great to be able to set a condition when the event occurs and trigger the Instruments (or debugger) to stop.
I fixed this. It appears that when the user expands the moviePlayer, the event lifecycle causes the view (MyAddDetailViewController) (that holds the subview (MyMoviePlayerController)) to execute viewWillDisappear & viewDidDisappear.
I mentioned that the code path created an additional viewController on the navigation stack, and that VC was making a brief appearance (evidenced by a viewWillAppear message) then going back into the background with viewWillDisappear. It still is not clear why that would cause the autoreleasePool to free up MyAddDetailViewController thus deallocating MyMoviePlayerController, but it is now clear that there was no strong reference to MyAddDetailViewController.
To fix, I created a property in the VC that pushes MyAddDetailViewController onto the navigation Stack to hold a strong reference to it.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// ... snip ...
self.myAddDetailViewControllerReference = [segue destinationViewController];
}
//
- (void)viewDidUnload {
[self setMediaAddDetailViewControllerReference:nil];
}
That takes care of the black screen/freeze.