When I use AudioToolBox for playing music, memory leaks heavily.
AVAudioPlayer *newMusicPlayer = [[AVAudioPlayer alloc] initWithData:data error:&error];
I use this code to play music. In iOS5 and iOS4, it works properly. But in iOS6, if data's size is 5M, all of the 5M leaked. And I can't see leak info in Instruments.
Is there anybody have the same problem? Any suggestion will be grateful.
All my audio code here(Using ARC):
@implementation ViewController
{
AVAudioPlayer *_player;
}
- (void)play
{
if (_player)
{
[_player stop];
_player = nil;
}
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"test.app/1.mp3"];
NSData *musicData = [[NSData alloc] initWithContentsOfFile:path];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:musicData error:nil];
player.volume = 1;
if (player)
{
_player = player;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 100, 100, 100);
[button setTitle:@"play" forState:UIControlStateNormal];
[button addTarget:self action:@selector(play) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
@end