我在自動釋放池中進行了大量的NSString操作。問題是我的程序有時會在游泳池流失之前崩潰。我想知道是否有辦法通過將nil分配給NSString來規避這個問題。對userLetters的分配發生了很多。見下面將自動釋放池中的NSString指定爲NSString
代碼之前
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
usersLetters = [usersLetters stringByReplacingCharactersInRange:NSMakeRange(indexUser, 1) withString:@"*"];
[pool drain];
後
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *temp = [usersLetters stringByReplacingCharactersInRange:NSMakeRange(indexUser, 1) withString:@"*"]; //remove that found character so it can't be reused again
usersLetters = nil;
usersLetters = temp;
temp = nil;
[pool drain];