ios - Memory management: CFStringRef manual release problem
phpcn_u1582
phpcn_u1582 2017-06-10 09:48:13
0
1
851

Recently I was looking at third-party source code, which involved some data types in the Core Foundation framework, and encountered some memory management crashes. I have forgotten many things about C voice. I hope to get guidance from the master here.

question:

//在网上例子上看到的这种方式创建的一个CFString的数组
CFStringRef keys[2];
keys[0] = CFSTR("key1");
keys[1] = CFSTR("key2");
//所以Core Foundation框架中的对象都不支持ARC,需要手动释放
CFRelease(keys);

As long as it runs, the following crash will occur

But I tried the code below, created a CFStringRef and then released it manually, it was no problem

CFStringRef aSTR = CFSTR("A STRING");
CFRelease(aSTR);

Actually, I am still confused about the method of creating arrays that I see on the Internet. I checked the usage of the Core Foundation framework on the Internet, but there are still relatively few, and I have no way to start.

Waiting online, hoping to get an effective answer, thank you~

phpcn_u1582
phpcn_u1582

reply all(1)
Ty80

keys is a pointer variable and is stored in the stack. It does not need to be released manually.
keys[0] keys[1] is CFStr and needs to be released manually

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template