Memory Leaks for typedef struct

2019-05-06 05:49发布

I m trying to remove memory 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?

4条回答
我想做一个坏孩纸
2楼-- · 2019-05-06 06:18

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];
查看更多
淡お忘
3楼-- · 2019-05-06 06:29

try relesing addressBook after allPeople

CFRelease(allPeople); CFRelease(addressBook);

This worked for me.

查看更多
【Aperson】
4楼-- · 2019-05-06 06:34

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.

查看更多
三岁会撩人
5楼-- · 2019-05-06 06:36

From the docs:

If you own an object, it is your responsibility to relinquish ownership (using CFRelease) when you have finished with it.

查看更多
登录 后发表回答