NSString potential leak

When I create and analyze my project on Xcode, I get a “warning” in the following line:

NSString *contactEmail = (NSString *)ABMultiValueCopyValueAtIndex(emailInfo, 0);

Message: Potential leak of object highlighted in line ... and stored in contactEmail.

Is there an error on this line?

UPDATE

I get the same “warning” with this line of code:

ABMultiValueRef emailInfo = ABRecordCopyValue(person, kABPersonEmailProperty);

But here I can not do this:

[emailInfo release];

I am developing for the iPhone.

+3
source share
2 answers

ABMultiValueCopyValueAtIndex- This is the "Copy" function, which should be "Create a rule . " You need to call CFReleaseto release it after the end of use.

NSString *contactEmail = (NSString *)ABMultiValueCopyValueAtIndex(emailInfo, 0);
...
if (contactEmail != nil)
  CFRelease((CFTypeRef) contactEmail);
+7
source
  • .
  • , -.

: :

NSString *contactEmail = [(NSString *)ABMultiValueCopyValueAtIndex(emailInfo, 0) autorelease];

( , , CFTypeRef.)

+1

Source: https://habr.com/ru/post/1741096/


All Articles