I am developing a project on iOS 7 using ARC, I want to release a private property when the viewController is released
Here is the TestViewController that is presented as a modal view controller, setting a value to the private property testAVPlayer in viewDidLoad:
//TestViewController.m
#import "TestAVPlayer.h"
@interface TestViewController () {
TestAVPlayer *testAVPlayer;
}
@end
- (void)viewDidLoad
{
[self setupPlayer];
}
- (void)setupPlayer {
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:[[NSBundle mainBundle] URLForResource:@"music" withExtension:@"mp3"]];
testAVPlayer = [TestAVPlayer playerWithPlayerItem:item];
[testAVPlayer setActionAtItemEnd:AVPlayerActionAtItemEndNone];
[testAVPlayer play];
}
- (void)dealloc {
NSLog(@"dealloc TestViewController: %@", self);
}
TestAVPlayer is a subclass of AVPlayer, I put a NSLog into the dealloc
// TestAVPlayer.h
#import <AVFoundation/AVFoundation.h>
@interface TestAVPlayer : AVPlayer
@end
// TestAVPlayer.m
#import "TestAVPlayer.h"
@implementation TestAVPlayer
- (void)dealloc {
NSLog(@"dealloc testAVPlayer: %@", self);
}
@end
When TestViewController is dismissed, the testAVPlayer seems never be released, I see the "dealloc TestViewController", but there is no "dealloc testAVPlayer" in console log
dealloc
should still get called when released by ARC. Something must be retaining the object, but I'm afraid there is not enough to go on here. – Brad Allred