如何解决本规范中的泄漏问题(启用ARC)?

时间:2013-02-25 04:49:51

标签: ios objective-c memory-leaks ios6 avaudioplayer

这是我的代码(启用了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];
}

}

Here is the detals of the leak enter image description here

1 个答案:

答案 0 :(得分:0)

我找到了泄漏的答案。

此漏洞归因于AVAudioPlayer基础类,Apple尚未修复。

因此AVAudioPlayer基础类的使用会导致泄漏。

Check This link for more detail