Avoiding static analyzer leak warnings when using objc_msgSend?

I have the following (simplified) code from a generic factory class:

- (id) invokeSetup: (id) object {
    // Just an example, subclasses delegate setup to a component that either returns +0 or +1 references
    return objc_msgSend(object, @selector(init));

- (id) newInstance {
    id object = objc_msgSend([NSString class], @selector(alloc));
    id replacement = [self invokeSetup: object];

    return replacement;

The analyzer produces a warning on the return replacement::

warning: Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected

I somehow need to tell the analyzer that the reference returned by - invokeSetup is +1. The above example is simplified, and in the real program, there are a few constraints:

  1. I cannot annotate invokeSetup with ns_returns_retained, since it is inherited, and there are other subclasses where invokeSetup returns +0 references. If it is a +1 or +0 can only be detected at runtime.

  2. I cannot change the name of any methods.

  3. The design is the way it is. There may be better designs, but that can't be changed here.

Is it possible to somehow tell ARC at the point of assignment (id replacement = ...) that the reference definitely is +1?

Thanks, Jochen


see http://stackoverflow.com/a/5833430/1313031 for a way to suppress static analyzer warnings in code

But yeah, the best thing to do would be to rename newInstance

Need Your Help

Disk usage for optimizing a partitioned MySQL-Table

mysql optimization space disk partition

I have a large MyISAM table with 3 million rows that has a size of 31 GB due to a 10KB blob in each row. The table has already 30 partitions. I want to optimize the table since I am going to remove...

Check if a url is a mercurial repository (like git ls-remote)


How can I check whether a URL points to a mercurial repository? With git, I would use git ls-remote $url and check the return value. Is there something similar for hg?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.