我试图从带有Core Data的SQLlite数据库中获取信息,并且在离开从DB获取NSManageObject的IBAction之后,应用程序崩溃时只出现了EXEC_BAD_ACCESS错误。
执行的代码是:
- (IBAction)abrir:(id)sender{
[openBrowser setTag:[sender tag]];
[self showOpenPanel:mWindow];
if (acceptCancelButton) {
NSString *auxN;
NSPredicate *auxP;
NSFetchRequest *auxFR;
NSError *err;
NSArray *array;
switch ([sender tag]) {
case 1:
auxN = [[[openBrowser selectedCell] stringValue] copy];
auxP =[NSPredicate predicateWithFormat:@"studyName == %@", auxN];
auxFR = [[NSFetchRequest alloc] init];
[auxFR setPredicate:auxP];
[auxFR setEntity:[NSEntityDescription entityForName:@"Study" inManagedObjectContext:managedObjectContext]];
[auxFR setIncludesSubentities:NO];
[auxFR setFetchLimit:1];
array = [managedObjectContext executeFetchRequest:auxFR error:&err];
if(array){
/*
Instanciamos un nuevo nsmanagedobject y lo cargamos con la información
leida de la BD
*/
actualStudy = [NSEntityDescription insertNewObjectForEntityForName:@"Study" inManagedObjectContext:managedObjectContext];
[actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyName"] forKey:@"studyName"];
[actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyPath"] forKey:@"studyPath"];
[actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyDescription"] forKey:@"studyDescription"];
[actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"compressRate"] forKey:@"compressRate"];
[actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"testDuration"] forKey:@"testDuration"];
NSLog(@"%@ %@ %@ %d %d",
[actualStudy valueForKey:@"studyName"],
[actualStudy valueForKey:@"studyPath"],
[actualStudy valueForKey:@"studyDescription"],
[[actualStudy valueForKey:@"compressRate"] floatValue],
[[actualStudy valueForKey:@"testDuration"] intValue]);
}else{
[Auxiliar showError:-15];
}
break;
...
}
}
}
代码执行正常,但当应用程序从调用返回时会显示以下消息:
The Debugger has exited with status 0.
[Session started at 2016-03-16 15:23:07 +0000.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
tty /dev/ttys001
Loading program into debugger…
sharedlibrary apply-load-rules all
warning: Unable to read symbols from "CoreData" (not yet mapped into memory).
Program loaded.
run
[Switching to process 3574]
Running…
[Switching to process 3574]
[Switching to process 3574]
[Switching to process 3574]
[Switching to process 3574]
(gdb) continue
Current language: auto; currently objective-c++
(gdb) continue
2016-03-16 15:23:36.720 eTracker[3574:a0f] CoreData /Users/admin/usabilimac/build/Debug/CoreData/ Prueba core data 600 0
Program received signal: “EXC_BAD_ACCESS”.
(gdb)
那个exec堆:
#0 0x7fff88de6f10 in objc_msgSend
#1 0x7fff836101d6 in _CFAutoreleasePoolPop
#2 0x7fff86d3e110 in -[NSAutoreleasePool drain]
#3 0x7fff81e27723 in -[NSApplication run]
#4 0x7fff81e203b0 in NSApplicationMain
#5 0x1000027f1 in main at main.mm:13
答案 0 :(得分:0)
问题出现在代码的其他部分,但正如我所说,这是同一阵列的多重释放。
消除所有显式释放调用后,EXEC_BAD_ACCESS消失。
感谢所有人试图回答我的问题。