On 17 Jul 2010, at 07:02, Kyle Sluder wrote:

> On Fri, Jul 16, 2010 at 10:36 PM, Rafael Cerioli
> <rafael.ceri...@gmail.com> wrote:
>> I guess I had something wrong, NSURLConnection does not do anything in a
>> background thread. It just operates in the main thread but "asynchronously"
>> thanks to the run loop.
> 
> Well, sort of. I believe what actually happens is that it uses a
> private helper thread to perform the communication but notifies its
> delegate on the main thread. But that's an implementation detail that
> I might well have wrong. All that matters is that something gets
> scheduled on the calling thread's runloop that is responsible for
> notifying the delegate.

That is correct. The connection is scheduled on the current thread, but the 
actual protocol implementations all happen on a single shared thread. 
Implementation detail though; doesn't matter to vast majority of uses!
> 
>> Quote from NSURLConnection class reference :
>> "At creation, a connection is scheduled on the current thread (the one where
>> the creation takes place) in the default mode"
>> That means, there is a lot of work done in the main thread. Even if the
>> connection is not scheduled in the runloop "tracking" mode (for the UI), I
>> guess the app would slow down at some point.
> 
> Guessing is not helpful. Start at the highest level of abstraction. If
> you can demonstrate with actual data that it poses a problem, then
> remove one layer of abstraction.

Hear hear!
> 
>> Isn't it better to use -[NSData initWithContentOfURL:] synchronous load
>> method in background thread ?Or is there something wrong about that kind of
>> use ?
> 
> It uses NSURLDownload, which has had its own share of problems:
> http://lists.apple.com/archives/Cocoa-dev/2007/Jun/msg00117.html

Really? I'd be very surprised if this were the case. Why download the file to 
disk if it's wanted in memory anyway?
> 
> In general, the answer to your Cocoa problems is not "spawn a thread."
> 
>> By the way, I never seen any bug about NSURLConnection running in background
>> threads on iPhone OS.
> 
> See above, but also here for the exact backtrace:
> http://lists.apple.com/archives/cocoa-dev/2008/May/msg03073.html
> 
> Again, this may have been fixed, the whole asynchronous thing might be
> a red herring for a more pervasive bug that also affects asynchronous
> use of the API, or (miracle of miracles) the bugs may have been fixed.
> But the received wisdom is do not use NSURLConnection synchronously,
> especially since it doesn't really give you any benefit to start with.
> 
> --Kyle Sluder
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
> 
> This email sent to cocoa...@mikeabdullah.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to