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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:22:31+00:00 2026-05-26T14:22:31+00:00

I am going to paste a code here and had a question regarding that

  • 0

I am going to paste a code here and had a question regarding that which I wanted to understand merely, based on the logical way.

@interface MySingleton : NSObject {
NSString *enteredCode; 
}

@property (nonatomic, retain) NSString *enteredCode;

@end


@synthesize enteredCode;

-(void) addInput:(NSString *) input
{ 
self.enteredCode = [self.enteredCode stringByAppendingString:input];
}

- (void)dealloc {
[enteredCode release];
}

@end

In my code, if I utilize “self.enteredCode = [self.enteredCode stringByAppendingString:input];”

everything works fine but “enteredCode = [self.enteredCode stringByAppendingString:input];” it gets exc_bad_access, and I am just wondering why this case be?

I am just trying to understand what difference really does it makes without having self there?

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-26T14:22:31+00:00Added an answer on May 26, 2026 at 2:22 pm

    This is not to do with singletons. When you do self.enteredCode you are going through the property which is set to ‘retain’. The stringByAppendingString method is a convenience method with returns an autoreleased object to you, meaning that it will be released at some point on the next run loop. You need to retain this value to stop it being released, which is fine when you assign it through the property as it is properly retained by you and you can use it as you like.

    When you reference the variable directory (without the self.) you bypass this and as such you don’t ever retain the value, the value is subsequently released and you reference bad memory and BOOOOOOOOM, bad access.

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

Sidebar

Related Questions

I am going to paste here my code and errors: #include stdio.h #include winsock2.h
I am not going to paste the code here and hope the statement of
I am not going to paste the code as I hope that is not
In 1987, I wrote the code I'm going to paste in a moment. The
For the past few years, I've generally accepted that if I am going to
Going back to my previous question on OCSP, does anybody know of reliable OCSP
Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx I'm trying to use the datacontext between
Going round in circles here i think. I have an activity called Locate; public
Going mad now. I have a MVC solution that i've upgraded from MVC 1
Is there a way to track if my javascript code is being used on

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.