Re: looking for a memory problem
Re: looking for a memory problem
- Subject: Re: looking for a memory problem
- From: Martin Wierschin <email@hidden>
- Date: Tue, 17 Jul 2012 19:17:58 -0700
> So my potential solution for this is:
>
> NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
> __block NSRange range = NSMakeRange(0, 0);
> while (range.location < [aString length]) {
>
> dispatch_sync(dispatch_get_main_queue(), ^{
> range = [checker checkSpellingOfString:aString startingAt:range.location];
> });
>
> // update range
> }
>
> Where this piece of code will run on multiple threads.
>
> Does this look like a reasonable approach to ensuring thread safety?
In addition to the potential for deadlocking that Mike warned about, it's probably best to be paranoid about +sharedSpellChecker. Hopefully that method uses a thread-safe singleton allocation (eg: via dispatch_once), but you never know. I'd move that method call to the main thread too.
However, by using this approach you're not really doing the spell checking work on a background thread. The work is going to be done synchronously on the main thread, blocking your GUI (and whatever else). Maybe you should investigate using -requestCheckingOfString:etc: instead.
~Martin
_______________________________________________
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