• 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 Hewitson <email@hidden>
  • Date: Wed, 18 Jul 2012 07:44:04 +0200

On 18, Jul, 2012, at 04:17 AM, Martin Wierschin <email@hidden> wrote:

>> 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.


Oh, this looks perfect. Don't know how I missed that API!

Thanks,

Martin

>
> ~Martin
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
    Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: email@hidden
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






_______________________________________________

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

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>)
 >Re: looking for a memory problem (From: Martin Wierschin <email@hidden>)

  • Prev by Date: Re: Help: Create, import and edit SVG object in Cocoa app
  • Next by Date: Re: looking for a memory problem
  • Previous by thread: Re: looking for a memory problem
  • Next by thread: Re: looking for a memory problem
  • Index(es):
    • Date
    • Thread