本文介绍了typedef结构的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I m trying to remove memory leaks. Below is my code.

currentTime = CFAbsoluteTimeGetCurrent();

CFTimeZoneRef currentTimeZone = CFTimeZoneCopyDefault();

todaysDate = CFAbsoluteTimeGetGregorianDate(currentTime, currentTimeZone);


[currentTimeZone release];
currentTimeZone = nil;

警告::/myclass.m:87:警告:接收器类型'CFTimeZoneRef'无效

Warning:::/myclass.m:87: warning: invalid receiver type 'CFTimeZoneRef'

如何释放typedef const结构的内存?

how to release memory for typedef const struct?

推荐答案

对于CFxxxCopyxxx,您应该使用CFRelease.

CFRelease(currentTimeZone);

CoreFoundation 类是,您的原始语句没有泄漏,只是需要强制转换.由于您直接使用CoreFoundation,因此我仍然建议您使用CFRelease.

There are CoreFoundation classes that are Toll-Free bridged and your original statement was not leaking but just needed a cast. I would still recommend using CFRelease since you were working directly with CoreFoundation.

[(NSTimeZone*)currentTimeZone release];

这篇关于typedef结构的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 21:15