[英]If statement causes a crash in the iOS device but not in the Simulator
因此,此代码可以正常运行,而不会导致iOS模拟器崩溃。 但是,在我的iOS设备(我的iPhone)上,这会导致崩溃! 谁能猜到为什么? 日志对任何地方都没有帮助。
NSInteger loops = 1;
char character = '.';
if ([futureTr rangeOfString:[NSString stringWithFormat:@"%c",character]].location != NSNotFound) {
NSArray *dotsArray = [futureTr componentsSeparatedByString:[NSString stringWithFormat:@"%c",character]];
loops = [dotsArray count];
if ([[dotsArray objectAtIndex:loops-1] isEqualToString:@""] || [dotsArray objectAtIndex:loops-1] == nil) {
loops--;
}
}
而且我知道,这是引起麻烦的语句,因为我将其注释掉,并且该应用程序正常运行! 怎么回事?
根据注释中的讨论,问题在于, futureTr
在某个时候被释放,然后此代码尝试使用现在释放的指针,从而导致“ BAD_ACCESS”异常。
对此变量进行适当的内存管理将缓解此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.