2013-02-25 84 views
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]; 
} 

} 

Here is the detals of the leak enter image description here

+0

ARC或不????? – 2013-02-25 04:51:20

+0

ARC已启用......... – 2013-02-25 04:52:05

+0

注释掉内存直到内存泄漏停止。内存泄漏发生的最后一行是原因。 – Patashu 2013-02-25 04:52:12

回答

0

我发现泄漏的答案。

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

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

Check This link for more detail