title: iOS bad access impossible to find
body: <p>I'm stuck with a stupid bad access since so many hours. I'm totally unable to find it.
  I hope some of you will be able to show me the answer into the light.
  In the code bellow it appear on the line : <code>NSString * stringCallVisit = [[NSString alloc]initWithFormat:.....</code>
  I can't understand, all the objects are local of the method except the parameter theIntervention.</p>
  
  <p>if i comment the method <code>NSString * stringCallVisit = [[NSString alloc]initWithFormat:...</code> the bad access don't appear even if i do <code>id obj = callVisit.injectionby;</code> instead of; So i suppose that the bad access is not from the callVisit object but certainly from the stringCallVisit object.
  But why i'm just instantiate it on the tine where the bad access appear.</p>
  
  <p>Thanks for your help,</p>
  
  <pre><code>-(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:&amp;error]mutableCopy];
  
  
  
  NSString *xml  = @"&lt;CallVisits&gt;";
  
  for(CallVisit *callVisit in callVisits) 
  {
  
      NSString * stringCallVisit = [[NSString alloc]initWithFormat:
                                    @"&lt;CallVisit&gt;"
                                    "&lt;id&gt;%@&lt;/id&gt;"
                                    "&lt;injectionby&gt;%@&lt;/injectionby&gt;"
                                    "&lt;injectionspot&gt;%@&lt;/injectionspot&gt;"
                                    "&lt;intervention_id&gt;%@&lt;/intervention_id&gt;"
                                    "&lt;fls&gt;%d&lt;/fls&gt;"
                                    "&lt;weight&gt;%d&lt;/weight&gt;"
                                    "&lt;height&gt;%d&lt;/height&gt;"
                                    "&lt;painAtInjection&gt;%d&lt;/painAtInjection&gt;"
                                    "&lt;created&gt;%@&lt;/created&gt;"
                                    "&lt;siteReaction&gt;%d&lt;/siteReaction&gt;"
                                    "&lt;technicalComplain&gt;%d&lt;/technicalComplain&gt;"
                                    "&lt;field1&gt;%d&lt;/field1&gt;"
                                    "&lt;field2&gt;%d&lt;/field2&gt;"
                                    "&lt;riskCompliance&gt;%d&lt;/riskCompliance&gt;"
                                    "&lt;reasonCompliance&gt;%@&lt;/reasonCompliance&gt;"
                                    "&lt;placebo&gt;%@&lt;/placebo&gt;"
                                    "&lt;needlereceived&gt;%@&lt;/needlereceived&gt;"
                                    "&lt;compliance&gt;%d&lt;/compliance&gt;"
                                    "&lt;psychologicalCondition&gt;%d&lt;/psychologicalCondition&gt;"
                                    "&lt;keepsegment&gt;%d&lt;/keepsegment&gt;"
                                    "&lt;/CallVisit&gt;",
                                    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:@"&lt;/CallVisits&gt;"];
  
  return xml;
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I did what you said but i'mm unable to understand the log and i don't received an adress to to the info malloc.
  I'm a bit lost :)</p>
  
  <p><strong>EDIT</strong>
  Here is the log. But it,s strange but know the app crash at an other place. </p>
  
  <pre><code>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) 
  </code></pre>