Iphone 仅在设备上运行应用程序时发生崩溃问题
因此,我有一个非常奇怪的问题,当我在模拟器上运行我的应用程序,并插入iPad(在连接电缆的设备上运行应用程序)时,一切正常。但是,在设备插上电源后,我尝试使用该应用程序在设备上运行后,它崩溃了。。尝试查看设备崩溃日志,我发现:Iphone 仅在设备上运行应用程序时发生崩溃问题,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,因此,我有一个非常奇怪的问题,当我在模拟器上运行我的应用程序,并插入iPad(在连接电缆的设备上运行应用程序)时,一切正常。但是,在设备插上电源后,我尝试使用该应用程序在设备上运行后,它崩溃了。。尝试查看设备崩溃日志,我发现: Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libobjc.A.dylib 0x3672bf78 objc_msgSend + 16
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3672bf78 objc_msgSend + 16
1 App 0x000ca834 -[AHAppImageData dealloc] (AHInstagramImageData.m:122)
2 libobjc.A.dylib 0x3672d16e _objc_rootRelease + 30
3 CoreFoundation 0x33d792e0 CFRelease + 88
4 CoreFoundation 0x33d8ea30 -[__NSArrayM removeObjectAtIndex:] + 288
5 CoreFoundation 0x33d84adc -[NSMutableArray removeAllObjects] + 64
6 App 0x000f717e -[AHImageDataSource clearDataSource] (AHImageDataSource.m:53)
7 App 0x000c0a36 __49-[AHMainViewController loadRequestWithURLString:]_block_invoke_0 (AHMainViewController.m:91)
8 libdispatch.dylib 0x32658c52 _dispatch_call_block_and_release + 6
9 libdispatch.dylib 0x3265aee0 _dispatch_main_queue_callback_4CF$VARIANT$mp + 188
10 CoreFoundation 0x33e032a6 __CFRunLoopRun + 1262
11 CoreFoundation 0x33d8649e CFRunLoopRunSpecific + 294
12 CoreFoundation 0x33d86366 CFRunLoopRunInMode + 98
13 GraphicsServices 0x37d68432 GSEventRunModal + 130
14 UIKit 0x36820cce UIApplicationMain + 1074
15 App 0x000b2860 main (main.m:16)
16 App 0x000b2820 0xb1000 + 6176
你知道为什么这只发生在设备上,而不是在插件或模拟器运行应用程序时吗
根据下面的评论,我展示了负责此操作的代码:
[[AHMyAppAPIClient sharedClient] getPath:requestURLPath parameters:nil
success:^(AFHTTPRequestOperation *operation, id response) {
[self.progressHUD_ hide:YES];
self.nextPaginationURL_ = [[response valueForKey:@"pagination"] valueForKey:@"next_url"];
[self.collectionView_.pullToRefreshView stopAnimating];
[[NSOperationQueue sharedOperationQueue] cancelAllOperations];
NSArray *arr = [response valueForKey:@"data"];
if ([arr count] > 0){
[[AHImageDataSource sharedDataSource] clearDataSource];
}
for (NSDictionary * data in arr){
AHInstagramImageData * imgData = [[AHInstagramImageData alloc] initWithData:data];
[[AHImageDataSource sharedDataSource] addObject:imgData];
[imgData release];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView_ setContentOffset:CGPointMake(0, 0)];
[self.collectionView_ reloadData];
});
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self.progressHUD_ hide:YES];
NSLog(@"Error fetching user data!");
NSLog(@"%@", error);
}];
以下是我设置数据源的方式:
extern NSString * const kClearDataSource;
@interface AHImageDataSource : NSObject
+ (AHImageDataSource *)sharedDataSource;
- (void) clearDataSource;
- (void) addObject:(id) object;
- (void) addObject:(id)object atIndex:(int) index;
- (int) count;
- (id) objectAtIndex:(int) index;
@end
NSString * const kClearDataSource = @"clearDataSource";
@interface AHImageDataSource()
{
NSMutableArray * imageDataSource_;
}
@property (nonatomic, retain) NSMutableArray * imageDataSource_;
@end
@implementation AHImageDataSource
@synthesize imageDataSource_;
+ (AHImageDataSource *)sharedDataSource {
static AHImageDataSource *_sharedClient = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedClient = [[self alloc] init];
});
return _sharedClient;
}
- (id)init {
self = [super init];
if (!self) {
return nil;
}
NSMutableArray * temp = [[NSMutableArray alloc] initWithCapacity:200];
self.imageDataSource_ = temp;
[temp release];
return self;
}
-(void) clearDataSource
{
if ([self.imageDataSource_ count] > 0){
[self.imageDataSource_ removeAllObjects];
}
}
- (void) addObject:(id) object
{
[self.imageDataSource_ addObject:object];
}
- (void) addObject:(id)object atIndex:(int) index
{
[self.imageDataSource_ insertObject:object atIndex:index];
}
- (int) count
{
return [self.imageDataSource_ count];
}
- (id) objectAtIndex:(int) index
{
if (index >= 0 && index < [self.imageDataSource_ count]){
return [self.imageDataSource_ objectAtIndex:index];
}
return nil;
}
- (void) dealloc
{
[super dealloc];
[imageDataSource_ release];
}
@end
extern NSString*const kClearDataSource;
@接口A图像数据源:NSObject
+(AHImageDataSource*)共享数据源;
-(void)clearDataSource;
-(void)addObject:(id)对象;
-(void)addObject:(id)object atIndex:(int)index;
-(int)计数;
-(id)对象索引:(int)索引;
@结束
NSString*const kClearDataSource=@“clearDataSource”;
@接口AHImageDataSource()
{
NSMutableArray*图像数据源;
}
@属性(非原子,保留)NSMutableArray*imageDataSource;
@结束
@数据源的实现
@综合图像数据源;
+(AHImageDataSource*)共享数据源{
静态AHImageDataSource*_sharedClient=nil;
静态调度一次预测;
一次发送(一次预测)^{
_sharedClient=[[self alloc]init];
});
返回共享客户;
}
-(id)init{
self=[super init];
如果(!self){
返回零;
}
NSMUTABLEARRY*temp=[[NSMUTABLEARRY alloc]initWithCapacity:200];
self.imageDataSource uz=temp;
[临时释放];
回归自我;
}
-(void)clearDataSource
{
如果([self.imageDataSource uCount]>0){
[self.imageDataSource uveAllObjects];
}
}
-(void)addObject:(id)对象
{
[self.imageDataSource uuaddobject:object];
}
-(void)addObject:(id)object atIndex:(int)index
{
[self.imageDataSource\uuInsertObject:object-atIndex:index];
}
-(int)计数
{
返回[self.imageDataSource uuCount];
}
-(id)对象索引:(int)索引
{
如果(索引>=0&&index<[self.imageDataSource\uuu计数]){
返回[self.imageDataSource\uObjectatindex:index];
}
返回零;
}
-(无效)解除锁定
{
[super dealoc];
[图像数据源发布];
}
@结束
编辑:
NSZombieEnabled似乎隐藏了这个问题。当我禁用NSZombieEnabled时,它现在在模拟器和设备上崩溃。看起来您过度释放了一个
ahinstagramagedata
实例,方法是将其放入字典,然后将保留计数降低到足以释放它的程度。然后,当它从字典中删除时,它会再次释放,并尝试为不再存在的对象释放内存
发布负责的代码,您可能会得到更详细的帮助。仅仅一个崩溃日志是不够的。我同意吉姆的观点,看起来像是双重释放 我会利用仪器“僵尸””配置文件来测试这种情况。它只能在模拟器中完成,但应该准确地向您显示双重发布的内容
一旦100%清楚了这一点,解决这种情况通常非常容易。我添加了负责这一点的代码。。希望你能多帮点忙。。因为我没有看到双重版本在哪里,这是触发错误的代码,但是错误可能是您设置数据源的地方。你能发布吗?我补充了我如何设置数据源。。让我知道这是否是您正在寻找的
self.imageDataSource\uuz=temp代码>看起来不正确。您使用的是属性语法,但使用的是私有ivar命名约定。由于您的代码是编译的,所以您使用的是一个属性,但您似乎混淆了它们之间的区别。如何定义此属性?我添加了上面关于如何定义此属性的代码。。我知道这是一种奇怪的做法,因为它可以在模拟器上正常工作,所以不能使用僵尸。。不,crashIt在模拟器上不一定能正常工作。当你过度发布某个东西时,它是否崩溃纯粹是运气使然。不过,过度发布仍然会发生,而且僵尸方法无论如何都应该有效。您可以在设备上运行代码时使用NSZombies。只是尝试使用仪器中的NSZombies,在设备上复制相同步骤时未发现任何泄漏您不是在寻找泄漏,而是在寻找双重发布,这基本上与泄漏相反。编辑您的方案并在“运行”部分的“选项”中启用僵尸对象。如果NSZombieEnabled隐藏了问题,则几乎可以肯定这是一个双重自由。很奇怪,仪器模板没有把它捡起来。。。