Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

EXEC BAD ACCESS - NSFetchRequest - After 300+ laps of a loop

I am running a loop through an array of Dictionary objects downloaded from a mysql server. The loop runs through a few delegate methods before saving each NSDictionary as a "Header" MObj in Core Data... The NSFetch request below is called to see if a MObj instance already exists in Core Data, to decide whether to Insert or Update it.

The code below works fine for anything up to around 300 records and then it produces a Exec Bad Access (code 2). What confuses me is why something is generating a Exec Bad Access after so many successful instances of the same process.


CODE

(1) This is the predicate method called to establish if the object already exists in coreData
-(void)addDict:(NSDictionary *)headerIn :(NSString *)accountID{
    
    NSDictionary *header = [NSDictionary dictionaryWithDictionary:headerIn];
    
    NSError *error;
    
    NSMutableArray *pArr = [NSMutableArray array];
    
    [pArr addObject:[NSPredicate predicateWithFormat:@accountID == %@",accountID]];
    [pArr addObject:[NSPredicate predicateWithFormat:@header_title == %@",[header valueForKey:@header_title]]];

    ListManager *listManager = [[ListManager alloc]init];
    NSArray *predicateArray = [listManager getCoreDataHeaderArray:pArr];

    Header *existingHeader = [predicateArray lastObject];
    
    if ...

}

(2) this is the predicate method called above
-(NSArray *)getCoreDataHeaderArray :(NSMutableArray *)pArray{
    
    
    NSError *error;
    
    NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@Header inManagedObjectContext:_context];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:pArray];
    [fetchRequest setReturnsObjectsAsFaults:NO];
    [fetchRequest setEntity:entityDesc];
    [fetchRequest setPredicate:predicate];
    
    NSArray *predicateArray = [_context executeFetchRequest:fetchRequest error:&error];
    
    NSArray *uniqueArray = [NSArray arrayWithArray:[self uniqueArrayByTitle:predicateArray]];
    
    return uniqueArray;
    
    
}


this is where the BAD EXEC ACCESS falls

o111c40z9z4t.png


Thread 1Queue : NSPersistentStoreCoordinator 0x17407ae00 (serial)
#0 0x0000000194cc23e4 in _nano_malloc_check_clear ()
#1 0x0000000194cc1064 in nano_malloc ()
#2 0x0000000194cb13e4 in malloc_zone_malloc ()
#3 0x0000000182b38b24 in __CFStringChangeSizeMultiple ()
#4 0x0000000182b370a0 in __CFStringAppendBytes ()
#5 0x0000000182b3202c in __CFStringAppendFormatCore ()
#6 0x0000000182b302a4 in _CFStringCreateWithFormatAndArgumentsAux2 ()
#7 0x0000000183976448 in -[NSPlaceholderString initWithFormat:locale:arguments:] ()
#8 0x0000000183976308 in +[NSString stringWithFormat:] ()
#9 0x00000001828123c0 in -[NSSQLAliasGenerator generateTableAlias] ()
#10 0x0000000182811f80 in -[NSSQLGenerator generateIntermediatesForFetchInContext:countOnly:] ()
#11 0x0000000182905fa0 in -[NSSQLGenerator newSQLStatementForRequest:ignoreInheritance:countOnly:nestingLevel:] ()
#12 0x00000001828eb0c0 in -[NSSQLAdapter _statementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] ()
#13 0x0000000182810278 in -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] ()
#14 0x000000018280fe84 in -[NSSQLCore newRowsForFetchPlan:] ()
#15 0x000000018280f594 in -[NSSQLCore objectsForFetchRequest:inContext:] ()
#16 0x000000018280f00c in -[NSSQLCore executeRequest:withContext:error:] ()
#17 0x00000001828db764 in __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke ()
#18 0x00000001828e4028 in gutsOfBlockToNSPersistentStoreCoordinatorPerform ()
#19 0x0000000100378f94 in _dispatch_client_callout ()
#20 0x000000010038308c in _dispatch_barrier_sync_f_invoke ()
#21 0x00000001828d5e98 in _perform ()
#22 0x000000018280ec5c in -[NSPersistentStoreCoordinator executeRequest:withContext:error:] ()
#23 0x000000018280d6e0 in -[NSManagedObjectContext executeFetchRequest:error:] ()
#24 0x00000001000e772c in -[ListManager getCoreDataHeaderArray:] at ...


Let me know if you need any more information


Any advice on how to resolve this issue would be greatly appreciated .. I am self taught and have a very limited understanding of debugging procedures .. I have activated Zombies but i cannot see where to go from there.

Sign In or Register to comment.