iphone - typedef 结构的内存泄漏

标签 iphone objective-c memory-leaks

我正在尝试消除内存泄漏。下面是我的代码。

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/

相关文章:

c - 在 C 中连接字符串指针时如何避免内存泄漏

iphone - iPad 模拟器网络流量不通过系统代理

iphone - 将UIButton框架设置在UIImgeView的中心

ios - IOS 教程中的 UnwindToList 未激活

iphone - 删除注释时 MKMapView 泄漏还是只有我泄漏?

windows - 调查内存泄漏

iphone - PFObject 没有成员用户名 Swift 2.0

iphone - cocoa 和 cocoa touch : is an object on the dictionary?

objective-c - 当值改变时 KVO 不触发

ios - 使用 Objective-C 捏合、平移和旋转 ImageView ,就像 Instagram 故事一样