Wednesday, 15 April 2015

iphone - UITextChecker: Memory Issue With Learning Thousands Of Words -



iphone - UITextChecker: Memory Issue With Learning Thousands Of Words -

i trying parse medical dictionary (.csv file) , larn words through uitextchecker: learnword method spellchecker approves medical terms valid words.

i calling method in thread amount of words in csv file around 50k.

- (void)parsemycsvfile{ (int = 1; < [csvcontent count]; i++) { nsstring *learntword = [nsstring stringwithformat:@"%@",[csvcontent objectatindex:i]]; nsstring *s = learntword; nscharacterset *donotwant = [nscharacterset charactersetwithcharactersinstring:@" ()\n\""]; s = [[s componentsseparatedbycharactersinset: donotwant] componentsjoinedbystring: @""]; if ([uitextchecker haslearnedword:s]){ nslog(@"skipped"); } else { [uitextchecker learnword:s]; // memory issue here nslog(@"learning"); } hud.detailslabeltext = [nsstring stringwithformat:@"%i of %i",i,[csvcontent count]]; } [self performselectoronmainthread:@selector(bgworkended) withobject:nil waituntildone:yes]; }

i have applied instruments time profiler , found out problem lies in line learning word within loop.

the app tries load dictionary till 5000 words (approx) , crashes.

any help appreciated.

thanks

you must not phone call uikit class methods on background thread--this will result in crashes. also, must create autorelease pool within method not leak objects. since uitextchecker must used on main thread, i'd recommend adding few words @ time, returning run loop don't stall app. display spinner user during process know it's doing.

iphone ios memory-management csv

No comments:

Post a Comment