0

I'm developing an application that uses NSURLConnection a lot. I want content to be loaded dynamically, so I have to implement a lot of delegates for this to work. In order to reduce the number of delegates, I created a class (AbstractURLConnection) that is < NSURLConnectionDelegate>.

I'm currently using a login view (and it's controller) to test the behavior of the NSURLConnectionDelegate class. Here are is my AbstractURLConnection class: AbstractURLConnection

In LoginViewController I then do the following:

@interface LoginViewController : UIViewController {
    AbstractNSUrlConnection *au;
}

@property (strong, nonatomic) AbstractNSUrlConnection <NSURLConnectionDelegate> *au;

- (void) handleResponse:(NSMutableData *) data;

and in the .m file:

- (IBAction)login:(id)sender {
    NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://myapp.dev:8887/users/login"]];
    au = [[AbstractNSUrlConnection alloc] initWithRequest:req sender:self withSelector:@"handleResponse:" andRequestMethod:[AbstractNSUrlConnection MethodTypePOST]];
}

- (void) handleResponse:(NSMutableData *) data{
     NSLog(@"called back");
}

When I run the application, my LoginView pops up and when I press the login button, the login function gets called. The connection is established and the callback method (handleResponse) is called too.

When I press the login button a second time, however, I get a EXC_BAD_ACCESS error to the handleResponse method.

I suppose that the sender is cleaned up when I press the button a second time, but I don't know how to solve this. Any idea what might cause this?

Thanks in advance,

Jordy

Kukiwon
  • 953
  • 8
  • 19
  • Try to clean the memory leaks in the code first, you can use `Product > Analyze` to see most of them. – A-Live Mar 21 '12 at 18:34
  • When I use `Product > Analyze`, nothing seems to happen. When I profile the application and reproduce the error, there are no memory leaks. XCode warns me about a potential memory leak in the following line though: `[self.sender performSelector: NSSelectorFromString(selector)];` – Kukiwon Mar 21 '12 at 18:40
  • Do you think you can get rid of that potential leak and test the issue ? – A-Live Mar 21 '12 at 18:49
  • Unfortunately I don't know how to suppress that warning. Any tips? – Kukiwon Mar 21 '12 at 19:08
  • Don't you have the details at `Issue navigator` (4th `Navigator` section where you can see all the warning during Build and analyzer messages during Analyze) ? You are usually able to expand the issue and selecting the elements will trigger a fancy arrow-drowing with a clear explanation right over the code. If there's no details, please post a complete Analyzer message. – A-Live Mar 21 '12 at 19:25
  • Here you go: [screenshot](http://postimage.org/image/fkly0fdhv/) – Kukiwon Mar 21 '12 at 19:36
  • Here's the related question http://stackoverflow.com/questions/7017281/performselector-may-cause-a-leak-because-its-selector-is-unknown But it seems not to help for that issue. Try to enable a zombie mode to get more details of the error and update your question: http://stackoverflow.com/questions/2190227/how-do-i-setup-nszombieenabled-in-xcode-4 – A-Live Mar 21 '12 at 21:43
  • I took a look at that question too but it did not help. I already had zombie mode enabled, but no zombies (not seeing anything in the output). A thing to note, the application doesn't crash, it actually pauses but every time I click resume, it pauses again. Here's the error: `Thread 1: Program received signal: "EXC_BAD_ACCESS".` – Kukiwon Mar 21 '12 at 23:44
  • If you are testing against the device, the crash-logs are located at `Devices` section of the `Organizer`, you can also try this solution: http://stackoverflow.com/questions/5605548/xcode-4-not-breaking-on-correct-line-on-exc-bad-access (your app 'has' crashed, EXC_BAD_ACCESS signal is not something you can ignore and resume). – A-Live Mar 22 '12 at 00:31
  • I've uploaded a part of the device's crash log: [crash log](http://pastebin.com/JwFyX9bP). I've enabled zombie mode, Guard Malloc, but still no success. Here's my output: [debugger output](http://pastebin.com/S5HLdFZK) Hope this helps, I really don't know what I'm doing wrong. Apparently the "LoginView" is deallocated, but it is initialized properly : `@property (strong, nonatomic) LoginViewController *lv;` and then in view did load: `lv = [self.storyboard instantiateViewControllerWithIdentifier:@"login"];` – Kukiwon Mar 22 '12 at 13:04

0 Answers0