The following code for some reason poradically works. I have checked the URL so many times it’s not funny (It returns plain text that I would like to parse). The code was 100% functional then it just stopped working and started giving me a EXC_BAD_ACCESS error.
There is nothing in the debugging output to post other than a line saying the output is switching to the process twice. (Except sometimes something about a double release.)
So far (as much as I can remember) I have tried:
- Reinstalling the app – it only has problems on the ‘Default’ run (not the first Run/initiate Run.)
- Running the URL in the browser (chrome, firefox, IE…)
- Putting the call in a
@try / @catchblock - Using
retain - Using a temp
NSAutoreleasePool - Splitting up / separating the elements of the call (along with loggin Everything – once it hits the error, nothing gets logged)
- Using the
dataWithContentsOfURLfunctions with the above
NSAutoreleasePool *tmpPool = [[NSAutoreleasePool alloc] init];
NSString *url_string = [self getNormalVersionDownloadURL];
NSLog(@"urlString: -%@-", url_string);
NSError *er;
NSURL *the_URL = [[NSURL URLWithString:url_string] retain];
NSString *version_String = [NSString stringWithContentsOfURL:the_URL encoding:NSASCIIStringEncoding error:&er];
NSLog(@"verions_string: -%@-", version_String);
if ([version_String length] < 16)
return;
[tmpPool release];
(NSAutoreleasePool and autorelease added due to http://discussions.apple.com/thread.jspa?threadID=1667544)
discussions.apple.com is currently down so I cannot read the discussion thread. At any rate:
Does
-getNormalVersionDownloadURLreturn an owned or a non-owned object? You only send-autoreleaseif the method returns an owned object.This should be
NSError *erinstead, or it should be initialised with the address of a variable of typeNSError *. Since the latter is uncommon and unnecessary, the following assumesNSError *er.+URLWithString:returns anNSURLobject that you don’t own, hence you don’t (auto)release it.Two problems::
+stringWithContentsOfURL:returns anNSStringobject that you don’t own, hence you don’t (auto)release it. Furthermore, the third parameter should be&erinstead ofer.