Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7792283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:08:16+00:00 2026-06-01T22:08:16+00:00

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

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:08:17+00:00Added an answer on June 1, 2026 at 10:08 pm

    see https://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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code(simplified). public class OrderProcessor { public virtual string PlaceOrder(string test)
Imagine I have the following code (simplified regarding my real context of course): <div
I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
Lets say we have the following models: (simplified) class Collection(models.Model): slug = models.SlugField() class
I have the following (simplified) result from SELECT * FROM table ORDER BY tick,refid
I am debugging some code and have encountered the following SQL query (simplified version):
The following simplified code doesn't work (because it sets the retrieved object reference to
Currently I have code like the following (simplified somewhat). Eventually, I've added more and
I have the following jQuery function (simplified): function doSomething(el, str) { el.find('.class').text(str)); } Don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.