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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:40:30+00:00 2026-06-03T21:40:30+00:00

What prevents the autoreleased instance of NSArray from being released before it’s used in

  • 0

What prevents the autoreleased instance of NSArray from being released before it’s used in the method it’s returned to?

- (NSArray *) f {
    return [NSArray array];
}

- (void) g {
    NSArray *a = [self f];
    // do something with a
}
  • 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-03T21:40:31+00:00Added an answer on June 3, 2026 at 9:40 pm

    What prevents the autoreleased instance of NSArray from being released
    before it’s used in the method it’s returned to?

    Autorelease pools are per thread. That is, an autoreleased object is, effectively, a delayed call to release that happens on a per thread basis.

    Thus, if there is no call to drain between the caller and the callee, there is no way the autoreleased object will be released because of a pool drain (barring serious threading stupidity).

    In general, pools are drained at very well specified times, like Kevin said:

    • the run loop will drain the pool at the bottom of each pass through the loop

    • dispatched blocks via GCD will execute within a pool context that’ll be drained “every now and then” (implementation detail). NSOperationQueue behaves similarly

    • other threads are responsible for doing it themselves

    Thus, in your simple example, the code execution is quite linear and, by inspection, there can be no drain in that thread of execution between the return and the use in the caller.

    (Note that this is also one of the reasons why retainCount is useless; it neither accounts for any “delayed release” calls caused by autorelease nor does it quantify any per-thread retains. In reality, you should think of retains/releases as being entirely per-thread; if you retain an object on a thread you should release it on the same thread unless you are explicitly transferring ownership from one thread to another.)

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

Sidebar

Related Questions

What prevents a modal view controller from being dismissed? I've found dismissModalViewControllerAnimated doesn't always
Currently my jQuery slider prevents the user from progressing if the range is 0-0
I heard that a private constructor prevents object creation from the outside world. When
I have a global app that prevents the mouse from moving into areas of
The OCaml GC imposes a global lock that prevents mutators (threads) from running in
Is there is easy command in MATLAB which prevents program from crashing when it
You may have heard of PawSense , a Windows-only utility that prevents keystrokes from
What is the Win32 api function that prevents the system from going into standby?
I'm trying to write an application that prevents certain key signals from propagating beyond
strncpy() supposedly protects from buffer overflows. But if it prevents an overflow without null

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.