AVAudioPlayerを複数立ち上げて音を二重で再生させると、
アプリ終了時、またはアプリ強制終了時にメモリリークする。
原因はよくわからんけど、それぞれのプレイヤーでcurrentTimeを0に設定したら落ちなくなった。
その他めも
- [audio1 stop]しても駄目だった
- [audio1 autorelease]はできなさげ
- ofTypeを指定しない場合も同じくメモリリークが発生する
ソース
#include <AVFoundation/AVFoundation.h>
...
@interface ViewController(){
AVAudioPlayer *audio1 ;
AVAudioPlayer *audio2 ;
}
@end
...
- (void)viewDidLoad
{
[super viewDidLoad];
[self playSound1:@"sound1" ];
[self playSound2:@"sound2" ];
}
...
- (void) playSound1 : (NSString *)file{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:file ofType:@"mp3"]];
audio1 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
audio1.currentTime = 0;
[audio1 play];
}
- (void) playSound2 : (NSString *)file{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:file ofType:@"mp3"]];
audio2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
audio2.currentTime = 0;
[audio2 play];
}