1

Using the analyzer on some Objective-C | Cocoa / Core Foundation code, I got a few error that I can't fix because I don't understand them.

Error #1: In an Objective-C class header, I declare this property.

@property(readwrite) CFMutableSetRef gClients;

In the body, I get the following error:

enter image description here

Question: Why is that a leak ? I store it in a property and dispose of it later. I thought ARC knew how to deal with CF "objects".

Error #2: Later on, I have this error when releasing the object:

enter image description here

Question: How can I take those two Analyzer warnings into account in order to create a code that actually works (self.gClients lives between calls to ClientInitialize and destroyAllClients) but does not get flagged?

1 Answer 1

2

ARC doesn't manage CF objects without manual intervention. There is work you need to do first.

See http://www.idryman.org/blog/2012/11/22/arc-best-practices-and-pitfalls/ at "ARC and toll-free bridging". There are special casting tricks with (__bridge_transfer).

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your reply. How do you suggest I do? gClients is declared as: @property(readwrite) CFMutableSetRef gClients; self.gClients = (__bridge_retained)CFSetCreateMutable(NULL, 0, NULL); leads to an error.
__bridge_retained is a type modifier, like volatile or const. Try (__bridge_retained CFMutableSetRef). Did you read the article? It's spelled out pretty explicitly there.
__bridge_retained is the opposite of what you and @Adrien want here. That will retain the object again, when it's already retained by the Create function that returned it. You want __bridge_transfer, which tells ARC “deal with this for me, will you?”. (This is mentioned in the article you linked to.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.