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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:39:27+00:00 2026-05-12T08:39:27+00:00

There are a lot of cases in which one would alloc an instance, and

  • 0

There are a lot of cases in which one would alloc an instance, and release it right after it’s being assigned to something else, which retains it internally.

For example,

UIView *view = [[UIView alloc] initWithFrame...];
[self addSubView:view];
[view release];

I have heard people suggesting that we go with autorelease rather than release right after.

So the above becomes:

UIView *view = [[[UIView alloc] initWithFrame...] autorelease];
[self addSubView:view];

What’s the best practice here? Pros and cons?

  • 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-05-12T08:39:27+00:00Added an answer on May 12, 2026 at 8:39 am

    In most cases, it wont really matter either way. Since -autorelease simply means that the object will be released at the end of the current iteration of the run loop, the object will get released either way.

    The biggest benefit of using -autorelease is that you don’t have to worry about the lifetime of the object in the context of your method. So, if you decide later that you want to do something with an object several lines after it was last used, you don’t need to worry about moving your call to -release.

    The main instance when using -release will make a noticeable difference vs. using -autorelease is if you’re creating a lot of temporary objects in your method. For example, consider the following method:

    - (void)someMethod {
        NSUInteger i = 0;
        while (i < 100000) {
            id tempObject = [[[SomeClass alloc] init] autorelease];
    
            // Do something with tempObject
    
           i++;
        }
    }
    

    By the time this method ends, you’ve got 100,000 objects sitting in the autorelease pool waiting to be released. Depending on the class of tempObject, this may or may not be a major problem on the desktop, but it most certainly would be on the memory-constrained iPhone. Thus, you should really use -release over -autorelease if you’re allocating many temporary objects. But, for many/most uses, you wont see any major differences between the two.

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

Sidebar

Related Questions

There are a lot of programs, Visual Studio for instance, that can detect when
There are cases when one needs a memory efficient to store lots of objects.
There's a lot of non-detailed questions on this one, so here goes. What is
I see there are lot's of examples in Ext JS where instead of actually
I know there a lot of similar questions to this, but I didn't find
There were a lot of promises and hopes, but did MS actually get around
There are a lot of tutorials that teach on how to validate XML against
There is a lot of discussions of Python vs Ruby, and I all find
There are a lot of reasons for sound not work (no speakers, speakers turned
There are a lot of SQL Top N questions on stackoverflow but I can'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.