简体   繁体   English

Memory typedef 结构泄漏

[英]Memory Leaks for typedef struct

I m trying to remove memory leaks.我正在尝试删除 memory 泄漏。 Below is my code.下面是我的代码。

currentTime = CFAbsoluteTimeGetCurrent();

CFTimeZoneRef currentTimeZone = CFTimeZoneCopyDefault();

todaysDate = CFAbsoluteTimeGetGregorianDate(currentTime, currentTimeZone);


[currentTimeZone release];
currentTimeZone = nil;

Warning:::/myclass.m:87: warning: invalid receiver type 'CFTimeZoneRef'警告:::/myclass.m:87: 警告:无效的接收器类型 'CFTimeZoneRef'

how to release memory for typedef const struct?如何为 typedef const struct 释放 memory?

With CFxxxCopyxxx you should use CFRelease .使用CFxxxCopyxxx你应该使用CFRelease

CFRelease(currentTimeZone);

Edit:编辑:

There are CoreFoundation classes that are Toll-Free bridged and your original statement was not leaking but just needed a cast.有一些CoreFoundation类是免费桥接的,您的原始声明没有泄漏,只是需要一个演员表。 I would still recommend using CFRelease since you were working directly with CoreFoundation.我仍然建议使用CFRelease ,因为您直接使用 CoreFoundation。

[(NSTimeZone*)currentTimeZone release];

From the docs:从文档:

If you own an object, it is your responsibility to relinquish ownership (using CFRelease) when you have finished with it.如果您拥有 object,您有责任在完成后放弃所有权(使用 CFRelease)。

You're using a CoreFoundation call, so instead of using Cocoa's release , you will want to call:您正在使用 CoreFoundation 调用,因此您不需要使用 Cocoa 的release ,而是要调用:

CFRelease( currentTimeZone);

in order to release the copied data.为了释放复制的数据。

try relesing addressBook after allPeople尝试释放地址簿毕竟人

CFRelease(allPeople); CFRelease(所有人); CFRelease(addressBook); CFRelease(地址簿);

This worked for me.这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM