如果我在 iPhone 代码中实现以下内容:
NSString* soundPath = [[NSBundle mainBundle] pathForResource:soundFile ofType:@"wav"];
SystemSoundID feedbackSound;
AudioServicesCreateSystemSoundID((__bridge CFURLRef) [NSURL fileURLWithPath:soundPath], &feedbackSound);
AudioServicesPlaySystemSound(feedbackSound);
我真的必须释放“feedbackSound”因为它是 C 代码吗?会不会漏?
我使用的是 ARC/iOS 6。
最佳答案
你应该。正确的调用方法是:
AudioServicesDisposeSystemSoundID
(reference)。
一般来说,ARC 只处理 Objective-C 对象。当您处理较低级别的框架(Core Graphics、AudioServices 等)时,许多调用将在“幕后”分配内存,您负责处理这些内存。在许多情况下,您有特定的方法来进行重新分配,就像您进行分配一样。
关于objective-c - 我是否需要释放 Objective-C 代码中的 C 变量(带有 ARC 的 iOS 6)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15173832/