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 8515889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:16:12+00:00 2026-06-11T05:16:12+00:00

I am using ARC but reading the MRR part of Objective-C, and it seems

  • 0

I am using ARC but reading the MRR part of Objective-C, and it seems like if a property of ViewController is (for non-ARC):

@property (retain, nonatomic) Foo *foo;

then the viewDidLoad of ViewController will need to do a release right after alloc and init:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.foo = [[Foo alloc] init];
    [self.foo release];

}

Otherwise, the retain will increment the reference count of the Foo object once when it is assigned to _foo (the instance variable), and alloc also increment the reference count once, so it is claiming ownership twice, and therefore, there needs to be a release right after the alloc and init?

I just feel it is a bit weird looking because an alloc is immediately followed by a release this way.

(If we do is a self.foo = [Foo fooByString: @"hello"], then one ownership is claimed by the autorelease pool, and one claimed by ViewController, and at the end of the event loop, the autorelease pool drains, and unclaim one ownership, and therefore the Foo object is correctly owned once only. (but if Foo doesn’t have such methods and only have alloc and init, then the immediate release is needed.))

  • 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-11T05:16:13+00:00Added an answer on June 11, 2026 at 5:16 am

    You’re essentially correct, though there are a few ways that it was typically done to make it look less awkward:

    Foo* someFoo = [[Foo alloc] init];
    self.foo = someFoo;
    [someFoo release];
    

    Or more succinctly:

    self.foo = [[[Foo alloc] init] autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just converted an old project to ARC using Xcode's automatic refactoring. @property (nonatomic,
Using ARC, I have a declared property of the following form: @property (nonatomic, strong)
I'm trying to use TPMultiLayoutViewController in a project using ARC, but am bumping into
I have written a method (shown below). The project is compiled using ARC, but
I want to bring a single Objective-C class written using ARC into an old
When using ARC for iOS, is there any difference between the following? @property (strong,
I have started using (ARC) with iOS 5, but I have a problem which
First, I should say I'm using ARC, so retain is not an option. The
By books first explains the problem (using ARC) about unvalid references, like in this
In objective-c, using ARC, when do BOOL (or int) properties get deleted? For example,

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.