Suppress: Static Analysis false positive.

I have a bit of code I'm calling from a Apple's StoreKit library that
looks something like:

Where you release the object in the callback function which leads to a
false positive for a memory leak.

I've dug through the documentation, but I can't find anything to help
me suppress this particular warning.

Thanks in advance,

The analyzer currently doesn't handle delegates in a clean way, so cases like these are helpful to see. Could you file a bugzilla report with this example? At the very least we can potentially silence the analyzer in these cases, and have it do something smarter over time.


In general I'm not so found of a general "silence this warning" annotation for the static analyzer, as really the goal is to make the analyzer smarter. Annotations (e.g., attribute(noreturn)) that educate the analyzer about program semantics are one thing, and they are good to use from a software engineering perspective because they document the assumptions of the code. But for cases where the analyzer is just outright confused, I'd prefer we get bug reports so we can just make it smarter. That way it benefits everyone who uses the analyzer. Chances are if you are seeing a false positive someone else has seen it too.

The analyzer can be a lot more clever than a compiler warning, so there we should never approach a false positive as "this is something the analyzer could never figure out." Even if solving the general analysis problem is hard, often identifying a case where the analyzer would have difficulty is trivial, and in such cases we can take a conservative approach of not issuing a warning.

Ideally you should avoid this when programming Cocoa. Retains and releases should be balanced within every method, with certain structured exceptions like accessors. When you do it as you have here it isn’t just harder for the static analyzer, it’s harder for you. For example, if the framework added cancellation via new instance method and corresponding delegate callback, you’d have to update your code to avoid a leak.

In this case, if possible, make the outstanding request a property of your object.

Cocoa Frameworks