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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:40:21+00:00 2026-05-24T03:40:21+00:00

In my last question ( here ), I had an issue where I was

  • 0

In my last question (here), I had an issue where I was getting an EXC_BAD_ACCESS because I was releasing the variable I had just allocated:

NSMutableArray* s = [[NSMutableArray alloc] init];
stack = s;
[s release];

should have been

NSMutableArray* s = [[NSMutableArray alloc] init];
stack = s;

However, stack is a retained property of my class. It’s declared like so:

@interface StateStack ()
@property (nonatomic, retain) NSMutableArray* stack;
@end

I was under the impression that when you assign a ‘retain’ variable, it automatically increments the retainCount of the object. So you are supposed to start by releasing your pointer (as here).

Why are these two cases different? Thanks!

  • 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-24T03:40:22+00:00Added an answer on May 24, 2026 at 3:40 am

    There is no such thing as a “retain variable”. It’s a retain property — meaning the setter method behind the property retains the new value and releases the old one. But assigning to a variable just assigns. In fact, the reason people generally recommend assigning directly to the instance variable in init is specifically so that it doesn’t go through the setter, because the setter could conceivably have side effects you don’t want in init (when your object isn’t fully constructed yet).

    Note: I’m talking about normal memory-management rules here. This is all different if you’re using ARC. But I assume you would have mentioned if you were.

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

Sidebar

Related Questions

Having had success with my last CLRS question, here's another: In Introduction to Algorithms
After my last, failed, attempt at asking a question here I'm trying a more
Hopefully the last NN question you'll get from me this weekend, but here goes
My last question was about getting the string representation of an object serialized to
I had a similar question answered Here There is a slight twist to the
I had a problem with the Django tutorial so I asked a question here.
It's late, I'm tired and forgot I had java homework. Last question is to
i had asked help on this question here Static member reclaiming memory and recovering
The last question I asked concerned how to bin data by x co-ordinate. The
My last question was somewhat narrower than this one. I am interested to know

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.