gpt4 book ai didi

objective-c - CFBridgingRetain 的静态分析器泄漏警告

转载 作者:行者123 更新时间:2023-12-02 07:37:37 24 4
gpt4 key购买 nike

有人能告诉我为什么会泄漏吗?我正在使用 CFRelease(),我认为它会释放 CFURLRef soundFileURLRef

调用函数“CFBridgingRetain”返回一个保留计数为 +1 的 Core Foundation 对象
对象泄漏:已分配的对象稍后未在此执行路径中引用,保留计数为 +1

  -(void) playGuitarNote:(NSString *)noteVal {

AudioServicesDisposeSystemSoundID(soundId);
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainBundle,CFBridgingRetain(noteVal), CFSTR("aiff"), NULL);
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundId);
AudioServicesPlaySystemSound(soundId);
CFRelease(soundFileURLRef);
noteVal = nil;

}

最佳答案

你不应该在那里调用 CFBridgingRetain()。你应该只使用 __bridge 转换:

CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainBundle,(__bridge CFStringRef)noteVal, CFSTR("aiff"), NULL);

您没有更改 noteVal 的所有权,您只是传递它并告诉编译器将其视为不同(但兼容)的类型。

关于objective-c - CFBridgingRetain 的静态分析器泄漏警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14805100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com