开发者

Memory Leaks for typedef struct

开发者 https://www.devze.com 2023-03-20 05:17 出处:网络
I m trying to remove memor开发者_如何学运维y leaks. Below is my code. currentTime = CFAbsoluteTimeGetCurrent();

I m trying to remove memor开发者_如何学运维y leaks. 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'

how to release memory for typedef const struct?


With CFxxxCopyxxx you should use 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. I would still recommend using CFRelease since you were working directly with 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.


You're using a CoreFoundation call, so instead of using Cocoa's release, you will want to call:

CFRelease( currentTimeZone);

in order to release the copied data.


try relesing addressBook after allPeople

CFRelease(allPeople); CFRelease(addressBook);

This worked for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消