[英]If statement causes a crash in the iOS device but not in the Simulator
So, this code runs properly, without causing any crashes in the iOS simulator. 因此,此代码可以正常运行,而不会导致iOS模拟器崩溃。 However, on my iOS device (my iPhone), this causes a crash!
但是,在我的iOS设备(我的iPhone)上,这会导致崩溃! Can anyone guess why?
谁能猜到为什么? The logs haven't helped anywhere.
日志对任何地方都没有帮助。
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--;
}
}
And I know that it's this statement that causes trouble, because I comment it out and the app just works fine! 而且我知道,这是引起麻烦的语句,因为我将其注释掉,并且该应用程序正常运行! What can be going on?
怎么回事?
Based on the discussion in the comments, the problem is that futureTr
is being released at some point and this code then attempts to use the now deallocated pointer resulting in the "BAD_ACCESS" exception. 根据注释中的讨论,问题在于,
futureTr
在某个时候被释放,然后此代码尝试使用现在释放的指针,从而导致“ BAD_ACCESS”异常。
Proper memory management of this variable will alleviate the problem. 对此变量进行适当的内存管理将缓解此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.