-(IBAction)play2;
{
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle,
(CFStringRef) @"Bear3", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
这是给我的错误:我的程序有内存泄漏
potential leak of an object allocated " CFBundleResourceURL
returns a Core Foundation object with a +1 retain count
避免讨论对象的实际保留计数(严格来说是实现细节),而是根据所有权来考虑对象。 – dreamlax
@dreamlax我正在讨论保留计数,因为在错误中提到了问题的关键。 – NJones
更仔细地阅读错误,它不告诉你*实际*保留计数,只是*相对*保留计数的所有权。 – dreamlax