Я наблюдал за своим следом памяти в Инструментах и заметил огромный всплеск, когда я вызываю метод ниже.Этот метод выполняет множество операций со строками, и мне интересно, нужно ли мне сохранять / освобождать строки NSStrings.Если кто-нибудь увидит, как улучшить этот метод, пожалуйста, дайте мне знать.
-(void)findWords:(NSString *)query {
//Removes Characters that aren't approved by me
NSString *usersLetters = [query substringWithRange:allLetters];
NSString *userLettersBackup = [query substringWithRange:allLetters];
//Loop over all words in a NSDictionary
for(NSString *word in wordSection)
{
int wordLength = [word length];
//Loop Over each char in the word
for (int i = 0; i < wordLength; i++)
{
char current = [word characterAtIndex:i];
//Loop Over each char in the usersletters
for (int indexUser = 0; indexUser <[usersLetters length]; indexUser++)
{
char compare = [usersLetters characterAtIndex:indexUser];
if(current == compare){
//Is this losing reference to the other userLetters?
//and retaining the previous value?
usersLetters = [usersLetters stringByReplacingCharactersInRange:NSMakeRange(indexUser, 1) withString:@"*"];
}
}
}
//Reset the UserLetters for looking at the next word
usersLetters = userLettersBackup;
}
}