Re: NSSpellChecker crashes after 64k words
Re: NSSpellChecker crashes after 64k words
- Subject: Re: NSSpellChecker crashes after 64k words
- From: Denis Stanton <email@hidden>
- Date: Thu, 14 Apr 2005 08:38:51 +1200
Hi Louis
I have finally found your response to my posting about SpellChecker. You posting had been downloaded on my other so I didn't get it until now. Fortunately there was enough info in the clippings that appeared in follow-on mails for me to catch your suggestion that I needed to use and NSAutoReleasePool and I skimmed forward in the book I'm reading to find and example. Simple wrapping
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
.............
[pool release];
around to contents of each nested loop solved the problem.
Thanks for your help.
Denis
On Apr 14, 2005, at 7:02 AM, Denis Stanton wrote:
Begin forwarded message:
From: "Louis C. Sacha" <email@hidden>
Date: 12 April 2005 10:07:17 PM
To: email@hidden
Cc: email@hidden
Subject: Re: NSSpellChecker crashes after 64k words
Hello...
I don't think your problem is specifically related to NSSpellchecker, it's probably just that too many autoreleased objects are being created within your loop.
The following example code crashes after a number of iterations similar to what you indicated (note that the word "mage" is apparently not a real word in American English, but it doesn't really make any difference whether the word is misspelled or not):
NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
NSString *testString = @"mage";
NSRange found;
unsigned i, j;
for (i=0; i<100; i++)
{
for (j=0; j<1024; j++)
{
found = [checker checkSpellingOfString:testString startingAt:0];
}
NSLog(@"count %i",(i*1024 + j));
}
If you add a couple lines to create and destroy a temporary autorelease pool within the loop doing all of the work, it should fix the problem. My choice to use 1024 iterations per pool was arbitrary, and you'd probably want to experiment a bit to figure out how often to do it to keep your app's memory footprint in check.
NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
NSString *testString = @"mage";
NSRange found;
unsigned i, j;
for (i=0; i<100; i++)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (j=0; j<1024; j++)
{
found = [checker checkSpellingOfString:testString startingAt:0];
}
NSLog(@"count %i",(i*1024 + j));
[pool release];
}
Hope that helps,
Louis
Hi
I have written a little program to solve a word puzzle. The program puts together possible words by appending permutations of supplied letters and syllables.
To determine whether the resulting string is a valid word I and using NSSpellChecker
NSRange wordRange = [spellChecker checkSpellingOfString: string startingAt: 0];
if (wordRange.length == 0) {
NSlog([NSString stringWithFormat: @" %@ is a word", string]);
}
The problem is my program fails with
Executable "MyApp" has exited due to signal 10 (SIGBUS).
after checking about 64,000 words. I guess it's hitting 64k (65,536) and this is some magic limit in NSSpellChecker.
Does anybody know how to reset whatever counter is causing NSSpellChecker to give up?
I thought at first it was accumulating a large ignored words list, so I added closeSpellDocumentWithTag but that didn't help, and I see that the ignored word list count is zero so that's not it.
Denis
Denis Stanton
email@hidden
Home: (09) 533 0391
mobile: 021 1433622
<x-tad-smaller>Denis Stanton
Orcon Internet Limited
(09) 480 9299
</x-tad-smaller><x-tad-smaller>http://www.orcon.net.nz
</x-tad-smaller><x-tad-smaller>
</x-tad-smaller>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden