Question

I got this problem with NSURLConnection instances, that after using an arbitrary number of them, they stop working and never call their delegate's methods. The way they are put to work is the following:

[[NSRunLoop mainRunLoop] addPort:self.port forMode:NSDefaultRunLoopMode];
[_connection scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[self.connection start];
[[NSRunLoop mainRunLoop] run];

The fact that they stop working after using a number of them, makes me think that they run out of any of the resources (perhaps ports on the main runLoop or something else).

It seems like everything is getting cleaned up pretty well

[_connection cancel];
[_connection release];

[[NSRunLoop mainRunLoop] removePort:self.port forMode:NSDefaultRunLoopMode];
[_port release];    
[super dealloc];

Do you guys see anything wrong with this approach? Any ideas why they might stop working?

Was it helpful?

Solution

According to Apple's documentation on NSRunLoop:

Run Loop Modes

NSRunLoop defines the following run loop mode.

extern NSString* const NSDefaultRunLoopMode;
extern NSString* const NSRunLoopCommonModes;
Constants

NSDefaultRunLoopMode

    The mode to deal with input sources other than NSConnection objects.

I noticed that you've used NSDefaultRunLoopMode for what appears to be NSConnection objects, although without seeing the rest of your code I'm really just speculating. Another thing you could try using is performSelector:onThread:withObject:waitUntilDone:, for it's possible one of your connections is caught in a race condition perhaps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top