我有一个类提供音乐播放器,在 ARC 下编译。这是初始化代码:
- (id) init{
self = [super init];
runningVolumeNotification = FALSE;
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
systemVolume = musicPlayer.volume;
NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"servo" ofType:@"mp3"];
AVAudioPlayer* p = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
[p prepareToPlay];
[p stop];
return self;
}
Instruments 报告线路 100% 泄漏:
AVAudioPlayer* p = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL];
我不知道问题出在哪里!