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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:35:25+00:00 2026-05-12T06:35:25+00:00

In my iPhone application, I have the following line in a constructor: self.myVar =

  • 0

In my iPhone application, I have the following line in a constructor:

self.myVar = myVar_in;

where myVar is a property and myVar_in is a parameter passed to the constructor.

When I run the code, I get an EXC_BAD_ACCESS error on this line. However, when I replace the line with:

[myVar release];
[myVar_in retain];
myVar = myVar_in;

the code runs fine. My property is declared like this:
NSNumber *myVar;
…
@property (retain) NSNumber *myVar;

The error is consistent and I’m positive it’s not a variable scope issue. Can someone explain this behavior?

EDIT: I’ve confirmed that myVar_in is valid right before the line(s) are executed. Here’s the actual code, although it won’t help much:

-(GetAddressRequestHelper*)initWithRequest:(ClientRequest*)request delegate:(id<ServerResponseDelegate>)delegate number:(NSNumber*)myVar_in location:(CLLocation*)location {
    self = [super initWithRequest:request delegate:delegate];

    if( self ) {
        // same behavior even if this line is uncommented!!!
        myVar_in = [NSNumber numberWithInt:123];

        // prints "myVar_in is 123"
        NSLog(@"myVar_in is %@",myVar_in);          

        // doesn't throw exception
        /*[myVar release];
          [myVar_in retain];
          myVar = myVar_in;*/

        // throws exception
        self.myVar = myVar_in;

        self.location=location;
    }
    return self;
}

EDIT2: I’ve found I still get the behavior when I explicitly initialize the param with myVar_in = [NSNumber numberWithInt:123];!

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-12T06:35:25+00:00Added an answer on May 12, 2026 at 6:35 am

    One critical difference between this code:

    [myVar release];
    [myVar_in retain];
    myVar = myVar_in;
    

    and this code:

    self.myVar = myVar_in;
    

    is the use of self to call the method (setMyVar).

    Almost certainly your object has been incorrectly created/allocated and self is a random value (in which case the assignment of myVar = myVar_in is scribling over random memory).

    Post the code showing your object creation/init call and for good how measure how myVar_in gets its value. Also post your init code (you can (very carefully) delete extraneous code, but since this is a weird case, any extraneous code might well be relevent…

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

Sidebar

Related Questions

How can I self-sign an iPhone application using Xcode? I have done the following:
I'm developing an iPhone application. I have the following property: @property (nonatomic, retain) Point2D*
I have following code which works fine in iPhone application but in iPad I
I have the following code in my iPhone application, warning memory leak! This is
I have following code in my application. NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]]; pathOfThumbNail has following
I continuously get the following warning when I build my iPhone application: Application failed
Within my iPhone application I have a common tab bar with three tabs that
Currently in my iPhone application I have about 200 image views, and I will
I'm developing an iPhone application that have a TabBarController with two tabs. Each tab
hai all, in my iphone application i have a login view with two text

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.