Objective c 使用ARC的AudioServicesPlaySystemSound内存泄漏

Objective c 使用ARC的AudioServicesPlaySystemSound内存泄漏,objective-c,memory-leaks,automatic-ref-counting,Objective C,Memory Leaks,Automatic Ref Counting,我需要一些帮助来解决这个内存泄漏问题。我正在使用ARC 该管线上存在潜在泄漏: NSURL *aFileURL = [NSURL fileURLWithPath:filePath isDirectory:NO]; 代码如下: // === Check if the game should play sound === // if (sound == YES) { //==== PLAY THE LOOSING SOUND ====// // Form a URL to the

我需要一些帮助来解决这个内存泄漏问题。我正在使用ARC

该管线上存在潜在泄漏:

NSURL *aFileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
代码如下:

// === Check if the game should play sound === //
if (sound == YES) {
    //==== PLAY THE LOOSING SOUND ====//
    // Form a URL to the sound file, which in init using the Path
    NSBundle *mainBundle = [NSBundle mainBundle];
    NSString *filePath = [mainBundle pathForResource:@"wrong2" ofType:@"wav"];
    NSURL *aFileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];

    // Create a sound ID, 
    SystemSoundID myID;
    // Register the sound
    AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)aFileURL, &myID) ;
    // Play the sound!
    AudioServicesPlaySystemSound(myID);
}

\uuu桥
替换保留的
\uu桥

\uu bridge\u retained
意味着您将
aFileURL
的所有权转让给
AudioServicesCreateSystemSoundID()
,该函数必须释放它(它没有)

我想你也应该打电话

AudioServicesDisposeSystemSoundID(myID)
当不再需要声音对象时

提示:当静态分析仪显示“潜在泄漏”警告时,单击警告左侧的蓝色图标,您将看到有关问题的详细信息