2013-02-25 53 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