Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nsoma007

macrumors newbie
Original poster
Jul 17, 2009
3
0
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
 
You return something called ret in getBaseUrl, but you do not create ret in that method. Also please use the code tags.
 
You return something called ret in getBaseUrl, but you do not create ret in that method. Also please use the code tags.

Thanks for the response. It was a typo error. I tried to type the code here. The return variable name is baseUrl.
 
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.
 
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.

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.
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.