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

  • Home
  • SEARCH
  • 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 8056973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:52:45+00:00 2026-06-05T08:52:45+00:00

I have understood how @autoreleasepool works, I have the newest version of xcode where

  • 0

I have understood how @autoreleasepool works, I have the newest version of xcode where ARC is supported.So I can use it, but I failt to understand how it works inside a class.
Let’s suppose that I have this interface:

@interface AppDelegate : NSObject <NSApplicationDelegate>
{
@private
    NSMutableDictionary* dictionary;
}

And that I allocate and initialize the dictionary in init method:

- (id) init
{
    self= [super init];
    if(self)
    {
        dictionary=[[NSMutableDictionary alloc]init];
    }
    return self;
}

In the dealloc method I can’t send to dictionary the release message, because I am under ARC.So when I usually allocate memory I do something like that:

@autoreleasepool
{
    NSMutableDictionary* dict=[[NSMutableDictionary alloc]init];
    < use it>
}

PS: Pardon syntax errors, I have written it directly without compiling.
But in the class, where do I put the “@autoreleasepool” block?

  • 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-05T08:52:47+00:00Added an answer on June 5, 2026 at 8:52 am

    You can place an @autoreleasepool block around any section of code, however you really shouldn’t do what I think you’re doing.

    Autorelease is much less efficient than allowing ARC to add in retain and release calls for you, and it’s potentially unsafe. Autorelease puts all of your objects in a “pool” and then when you’re out of scope and/or whenever it decides to dump the pool, it “drains” the pool and the objects’ retain counts get decremented by one.

    The short answer: Leave out the @autorelease blocks completely unless Apple says otherwise in the documentation or the template (for example, main.m will have an @autoreleasepool in it).

    This means that your objects could potentially get released before you really wanted them to. @autoreleasepool blocks are more useful for when you have a very tight loop of code that’s going to instantiate and then discard a massive amount of objects. For example, a for loop that processes a huge database and allocates string objects and then uses those string objects to fill the properties of instances of a class you’ve created. In this case, ARC may not release those objects reliably while you’re inside the for loop and you may need to create an autorelease pool.

    However, ARC not doing the right thing in a tight loop isn’t very common. It’s really more of a non-ARC concept, where you use an NSAutoreleasePool and you manually drain it.

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

Sidebar

Related Questions

I think I have understood how MeasureOverrride works, but I am trying to use
I thought I understood sed but I guess not. I have the following two
I have understood that if I use EJB in Spring context, I get all
I thought I have understood the XML layout of Android, but it seems that
I want to understand exactly what unit test means. From what I have understood
I am supposed to have understood Cloures properly in Javascript, but I obviously didn't...
I've been programming in Perl for a while, but I never have understood a
I think I have understood a particular situation as described below, but I lack
i have understood that a namespace is a container of units; but i haven't
I have heard about Flash Builder 4.5.1.As I have understood, one can make an

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.