• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: looking for a memory problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: looking for a memory problem
      • From: Martin Hewitson <email@hidden>
References: 
 >looking for a memory problem (From: Martin Hewitson <email@hidden>)
 >Re: looking for a memory problem (From: Charlie Dickman <email@hidden>)
 >Re: looking for a memory problem (From: Martin Hewitson <email@hidden>)
 >Re: looking for a memory problem (From: Martin Hewitson <email@hidden>)
 >Re: looking for a memory problem (From: Fritz Anderson <email@hidden>)
 >Re: looking for a memory problem (From: Martin Hewitson <email@hidden>)
 >Re: looking for a memory problem (From: Martin Hewitson <email@hidden>)

  • Prev by Date: Re: looking for a memory problem
  • Next by Date: Looking for better solution than this old hack
  • Previous by thread: Re: looking for a memory problem
  • Next by thread: Re: looking for a memory problem
  • Index(es):
    • Date
    • Thread