[NSString stringWithContentsOfURL:...], threads, and 10.5.4, xcode 3.1
[NSString stringWithContentsOfURL:...], threads, and 10.5.4, xcode 3.1
- Subject: [NSString stringWithContentsOfURL:...], threads, and 10.5.4, xcode 3.1
- From: "email@hidden" <email@hidden>
- Date: Mon, 21 Jul 2008 14:02:30 -0700
i have been using +[NSString stringWithContentsOfURL:encoding:error:]
in my app to obtain stock quotes from yahoo. i issue this in one (or
more) threads to get values for one (or more) stocks. i'm not quite
sure when this stopped working successfully, but it is definitely not
working reliably on 10.5.4 with xcode 3.1 and with NO garbage
collection.
by not reliably i mean that i will quite frequently (but not always)
get the following message on the console:
*** -[CFURL _cfurl]: message sent to deallocated instance 0x290180d0
and the relevant stack trace is:
#0 0x95ae3907 in ___forwarding___
#1 0x95ae3a12 in __forwarding_prep_0___
#2 0x95ab5d42 in CFURLCopyPath
#3 0x92350d4e in createNotificationName
#4 0x9235113c in __PrivateCookieStorageDeallocate
#5 0x95a66788 in _CFRelease
#6 0x923510d6 in __CFHTTPCookieStorageDeallocate
#7 0x95a66788 in _CFRelease
#8 0x92306c2d in _CFURLRequestDeallocate
#9 0x95a66788 in _CFRelease
#10 0x9230ac1b in __CFCachedURLResponse::SetRequest
#11 0x9230ab0e in AddCacheTask
#12 0x92308603 in __CFURLCache::CopyResponseForRequest
#13 0x92307b38 in _CFURLConnectionSendCallbacks
#14 0x92307573 in muxerSourcePerform
#15 0x95a64615 in CFRunLoopRunSpecific
#16 0x95a64cf8 in CFRunLoopRunInMode
#17 0x9232ab42 in CFURLConnectionSendSynchronousRequest
#18 0x952ac80b in +[NSURLConnection
sendSynchronousRequest:returningResponse:error:]
#19 0x9537afab in -[NSString initWithContentsOfURL:encoding:error:]
#20 0x9537a51f in +[NSString stringWithContentsOfURL:encoding:error:]
#21 0x00147f00 in +[StockSupport_Yahoo(PrivateUtilities)
historicStockValue:asOfDate:error:] at StockSupport_Yahoo.mm:296
and the relevant snippet of my code is:
NSURL* lookupURL = [[NSURL alloc] initWithString: urlLookupString];
NSError* lookupError = nil;
NSString* csvString = [NSString stringWithContentsOfURL:
lookupURL encoding: NSUTF8StringEncoding error: &lookupError];
...
[lookupURL release];
i've worked around it for the time being by actually calling
+[NSString stringWithContentsOfURL:encoding:error:] from my main
thread, but not only does this slow down the app (since requests are
now sequential), but it also prevents the user from aborting the
requests (since the main/ui thread is now busy).
can anyone explain the above error? can anyone indicate whether or
not +[NSString stringWithContentsOfURL...] is thread safe? (i was
under the impression that the foundation classes NSString, NSURL, and
NSData were all thread safe, and as i said above, this used to work.)
thanx for any help/answers/advice/etc.
thanx,
ken
ps. it would take a fairly significant restructuring to use
asynchronous NSURLConnection requests, so i'd like to avoid that if
possible... especially since i had thought i had solved this problem
by performing the requests in threads.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden