1
这里是我的代码(启用ARC),可以看到内存泄漏。如何解决此代码泄漏(启用ARC)?
请帮我解决这个问题。
- (void) setMusic
{
/*
Initialise and set the music for the game.
*/
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"actionMusic" ofType:@"caf"]];
NSError *error = nil;
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (!error)
{
_audioPlayer.delegate = self;
if(_musicFlag)
{
[_audioPlayer play];
}
[_audioPlayer setNumberOfLoops:INT32_MAX];
}
error = nil;
url =nil;
url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"pew" ofType:@"wav"]];
_moveMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (!error)
{
_audioPlayer.delegate = self;
}
error = nil;
url =nil;
url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Won" ofType:@"wav"]];
_winningMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (!error)
{
_winningMusic.delegate = self;
[_winningMusic setNumberOfLoops:1];
}
}
ARC或不????? – 2013-02-25 04:51:20
ARC已启用......... – 2013-02-25 04:52:05
注释掉内存直到内存泄漏停止。内存泄漏发生的最后一行是原因。 – Patashu 2013-02-25 04:52:12