我正在尝试消除内存泄漏。下面是我的代码。
currentTime = CFAbsoluteTimeGetCurrent();
CFTimeZoneRef currentTimeZone = CFTimeZoneCopyDefault();
todaysDate = CFAbsoluteTimeGetGregorianDate(currentTime, currentTimeZone);
[currentTimeZone release];
currentTimeZone = nil;
警告::/myclass.m:87:警告:无效的接收器类型'CFTimeZoneRef'
如何为 typedef const struct 释放内存?
最佳答案
对于CFxxxCopyxxx
,您应该使用CFRelease
。
CFRelease(currentTimeZone);
编辑:
有CoreFoundation Toll-Free bridged 类并且您的原始声明没有泄漏,只是需要类型转换。我仍然建议使用 CFRelease
,因为您直接使用 CoreFoundation。
[(NSTimeZone*)currentTimeZone release];
关于iphone - typedef 结构的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6679815/