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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:41:02+00:00 2026-05-16T08:41:02+00:00

I know that if I get an object, for example an NSArray, with a

  • 0

I know that if I get an object, for example an NSArray, with a method like [NSArray array], it will be autoreleased. So I don’t have to do a release myself. My question is, do I have to retain it after I get it this way? I wouldn’t have thought so, since the count starts at 1 and it won’t be released until the pool is released, but I’ve gotten a few bad access errors from these objects when I don’t. So to fix them, I’m retaining these objects, and then releasing them myself later. What’s going on in this case? Am I still not grasping objective-c memory management?

  • 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-16T08:41:03+00:00Added an answer on May 16, 2026 at 8:41 am

    I heartily advise you to stop thinking about retain counts. Instead, think about ownership: do you want to claim a piece of ownership of an instance (i.e. do you want to make sure it stays around until you say otherwise)? If so, -retain it. Otherwise, do not -retain it. Anytime you retain an ownership interest in an instance, you must -release that interest some time in the future or the instance will never be deallocated.

    You can assume that any method that doesn’t match the alloc/new/copy pattern returns instances in which you do not have an ownership interest. If you want them to stick around beyond the current stack frame, retain them.

    For this and all other Objective-C memory questions, read the Memory Management Programming Guide. Then re-read it. Again. It is the authoritative reference on the subject. It will be your friend.

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

Sidebar

Related Questions

I know that in J2ME I can get a byte[] object from a String
Let's say that I have a object that looks like this var object =
I would like to know how I can get the metadata of an object
In code: //I know that to get this effect (being able to use it
I know that I can get the true bits with the simple loop, but
I know that I can get word completion through CTRL+N & CTRL+P and code
I know that I can get a POSIX int file handle from NSURL by
I know that in Oracle I can get the generated id (or any other
I know that the specification exactly defines it but cannot get what is the
I know enough to know that we need to get our application to deploy

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.