这么多小时以来,我一直被一个愚蠢的错误访问所困扰。我完全找不到它。
我希望你们中的一些人能够向我展示答案。
在下面的代码中,它出现在行中:NSString * stringCallVisit = [[NSString alloc]initWithFormat:.....
我无法理解,除了参数 theIntervention 之外,所有对象都是方法的局部对象。
如果我注释方法 NSString * stringCallVisit = [[NSString alloc]initWithFormat:...
即使我执行 id obj = callVisit.injectionby; 也不会出现错误访问;
而不是;所以我认为错误的访问不是来自 callVisit 对象,而是来自 stringCallVisit 对象。
但为什么我只是在出现错误访问的尖齿上实例化它。
谢谢你的帮助,
-(NSString*)getCallVisitForIntervention:(Intervention*)theIntervention
{
NSManagedObjectContext *context = [iPad_TestAppDelegate mainContext];
NSError *error;
NSFetchRequest *requestCallVisit = [[NSFetchRequest alloc]init];
[requestCallVisit setEntity:[NSEntityDescription entityForName:@"CallVisit" inManagedObjectContext:context]];
NSPredicate *predicateInterventionID = [NSPredicate predicateWithFormat:@"intervention_id = %@",theIntervention.id];
[requestCallVisit setPredicate:predicateInterventionID];
NSMutableArray *callVisits = [[context executeFetchRequest:requestCallVisit error:&error]mutableCopy];
NSString *xml = @"<CallVisits>";
for(CallVisit *callVisit in callVisits)
{
NSString * stringCallVisit = [[NSString alloc]initWithFormat:
@"<CallVisit>"
"<id>%@</id>"
"<injectionby>%@</injectionby>"
"<injectionspot>%@</injectionspot>"
"<intervention_id>%@</intervention_id>"
"<fls>%d</fls>"
"<weight>%d</weight>"
"<height>%d</height>"
"<painAtInjection>%d</painAtInjection>"
"<created>%@</created>"
"<siteReaction>%d</siteReaction>"
"<technicalComplain>%d</technicalComplain>"
"<field1>%d</field1>"
"<field2>%d</field2>"
"<riskCompliance>%d</riskCompliance>"
"<reasonCompliance>%@</reasonCompliance>"
"<placebo>%@</placebo>"
"<needlereceived>%@</needlereceived>"
"<compliance>%d</compliance>"
"<psychologicalCondition>%d</psychologicalCondition>"
"<keepsegment>%d</keepsegment>"
"</CallVisit>",
callVisit.id,
callVisit.injectionby,
callVisit.injectionspot,
callVisit.intervention_id,
[callVisit.fls doubleValue],
[callVisit.weight doubleValue],
[callVisit.height doubleValue],
[callVisit.painAtInjection intValue],
callVisit.created,
[callVisit.siteReaction intValue],
[callVisit.technicalComplain intValue],
[callVisit.field1 intValue],
[callVisit.field2 intValue],
[callVisit.riskCompliance intValue],
callVisit.reasonCompliance,
callVisit.placebo,
callVisit.needlereceived,
[callVisit.compliance intValue],
[callVisit.psychologicalCondition intValue],
[callVisit.keepsegment intValue]];
xml = [xml stringByAppendingString:stringCallVisit];
[stringCallVisit release];
id obj = callVisit;
}
[callVisits release];
[requestCallVisit release];
xml = [xml stringByAppendingString:@"</CallVisits>"];
return xml;
}
编辑:
我按照你说的做了,但我无法理解日志,而且我没有收到信息 malloc 的地址。 我有点迷路:)
编辑 这是日志。但这很奇怪,但知道应用程序在其他地方崩溃了。
GuardMalloc[iPad Test-7405]: Failed to VM allocate 397648 bytes
GuardMalloc[iPad Test-7405]: Explicitly trapping into debugger!!!
sharedlibrary apply-load-rules all
Error in re-setting breakpoint 1:
Catchpoint 2 (throw)iPad Test(7405,0xaccab2c0) malloc: recording malloc stacks to disk using standard recorder
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
Error in re-setting breakpoint 1:
Error in re-setting breakpoint 1:
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Current language: auto; currently objective-c
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
GuardMalloc[iPad Test-7405]: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
No memory available to program: call to malloc failed
(gdb)
最佳答案
设置NSZombieEnabled , MallocStackLogging , 和 guard malloc在调试器中。然后,当您的应用程序崩溃时,在 gdb 控制台中输入:
(gdb) info malloc-history 0x543216
将 0x543216
替换为导致崩溃的对象的地址,您将获得更有用的堆栈跟踪,它应该可以帮助您查明代码中导致问题的确切行.
See this article for more detailed instructions.
编辑:看起来您可能内存不足。您是否实现了 didReceiveMemoryWarning
方法?如果是这样,请将 NSLog 放入其中以查明您是否内存不足。
关于iphone - 无法找到 iOS 错误访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7829808/