【发布时间】:2012-09-23 14:11:44
【问题描述】:
当我使用 AudioToolBox 播放音乐时,内存泄漏严重。
AVAudioPlayer *newMusicPlayer = [[AVAudioPlayer alloc] initWithData:data error:&error];
我使用此代码播放音乐。在 iOS5 和 iOS4 中,它可以正常工作。但是在iOS6中,如果数据大小为5M,则5M全部泄露。而且我在 Instruments 中看不到泄漏信息。
有人遇到同样的问题吗?任何建议将不胜感激。
我所有的音频代码都在这里(使用 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
【问题讨论】:
-
检查发行说明确实有一些变化!在 ios6
-
您是否观察到iOS模拟器或设备中的内存泄漏?还是两者兼而有之?
-
在模拟器中。事实上,我无法在 4.5 的 Instruments 中获取设备上的 objc 符号,只有 c 符号显示
-
@matheszabi 我在developer.apple.com/library/ios/#releasenotes/General/… 中没有找到它,有没有提到它?谢谢
-
@OpenThread SO(和我)的几个提问者仅在模拟器上遇到了同样的问题。尝试在设备上分析您的应用,如果它没有泄漏,请不要担心。
标签: iphone avaudioplayer ios6