0
votes

I use ARC, for the ASIHTTPRequest-Files I have the special compiler linker flag, so they don't use ARC. Now I create an ASIHTTPRequest like this:

...

@property(nonatomic,strong) ASIFormDataRequest *request;

@syntesize request

...

self.request = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:API3]];
self.request.delegate=self;
[self.request startAsynchronous];

If the view closed before the request finished, I get a EXEC_BAD_ACCESS, because the view is already released. If I call a

[self.request clearDelegateAndCancel]

The request didn't stop and the App still continue to crash. I tried to call clearDelegateAndCancel on the main Thread and with performSelector afterDelay, but with the same results. When I enable the LOG output of ASIHTTPRequest, I see that the methods get called, and also the internal Function [self cancel] in ASIHTTPRequest.m is called, but the request didn't stop, I see it because of the Network Activity Indicator.

Does anyone else have this problem, or know how to solve?

2

2 Answers

2
votes

that is probably because your viewcontroller, that is the ASI delegate, is not managed as an arc weak pointer by ASI, and therefore not automatically updated to nil when the viewcontroller gets deallocated. You should implement dealloc in your arc viewcontroller in order to prevent ASI from calling back the non existing delegate (the viewcontroller)

- (void)dealloc
{
   [request clearDelegatesAndCancel];
}

even viewDidUnload should cancel the ASI request zeroing therefore the delegate

- (void)viewDidUnload
{
    [self.request clearDelegatesAndCancel];
    self.request = nil;

    [super viewDidUnload];
}
2
votes

You can disable ARC for that one class

When you migrate a project to use ARC, the -fobjc-arc compiler flag is set as the default for all Objective-C source files. You can disable ARC for a specific class using the -fno-objc-arc compiler flag for that class.

In Xcode, go to target Build Phases tab > open the Compile Sources group to reveal the source file list > double-click the file for which you want to set the flag > enter -fno-objc-arc in the pop-up panel, then click Done.