EXC_BAD_ACCESS: Please help

Discussion in 'iOS Programming' started by nsoma007, Jul 17, 2009.

  1. nsoma007 macrumors newbie

    Joined:
    Jul 17, 2009
    #1
    I have this class method in one of the classes.

    Code:
    @implementation MyStaticClass
    
    +(NSString*)getBaseUrl {
    	NSString* baseUrl = [[NSString alloc] initWithFormat:@"%@://%@", @"http", @"www.mywebsite.com"];
    	return baseUrl;
    }
    ...
    ...
    @end
    
    When I call this method from another place, I get an EXC_BAD_ACCESS at the end of the method execution.

    Code:
    -(IBAction)savePressed:(id)sender {
    	// save button is pressed
    	// validate the login credentials to save the data	
    	NSString* page = [MyStaticClass getBaseUrl];
    	NSString* postData = @"username=name@gmail.com&password=123&x=76&y=12";
    	request = [[HttpRequestHandler alloc] initWithPage:page postData:postData delegate:self];
    } // -> EXC_BAD_ACCESS here
    
    I am a newbie and I appreciate if any one shed some light.

    Thanks
    soma
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You return something called ret in getBaseUrl, but you do not create ret in that method. Also please use the code tags.
     
  3. nsoma007 thread starter macrumors newbie

    Joined:
    Jul 17, 2009
    #3
    Thanks for the response. It was a typo error. I tried to type the code here. The return variable name is baseUrl.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    You'll want to retain baseUrl if you're returning it. Otherwise, it gets released at the end of the method, since it is just a local variable.
     
  5. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #5
    Actually his class method has a bug; he's not auto-releasing the baseURL string when he returns it and he should be *but* that means it can't be the cause of the bad access error as it will never be released.
     
  6. nsoma007 thread starter macrumors newbie

    Joined:
    Jul 17, 2009
    #6
    Solved

    Thanks for all your responses. It was a dumb mistake by me. I released an object which was marked "autorelease".

    Code:
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:baseURL];
    
    [request release]; // this was the issue
    
     

Share This Page