2

I'm trying to make app with xcode 4.2 and i'm really confused whay happen this. Could someone help me an explain me why have error in lines when appear &error

Passing address of non-local object to __autoreleasing parameter for write-back

RootViewController.h

RootViewController.m

Javier
  • 1,975
  • 3
  • 24
  • 46
  • 1
    The solution... In .h --> NSError *__autoreleasing * error; In.m --> [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:error]; – Javier Nov 29 '11 at 12:42

1 Answers1

4

It would have been easier to diagnose the error without having to guess at the line number on which it occurs, but I think the issue is your use of the error instance variable to pass as the error here:

30    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];

also here

49    [fm removeItemAtPath:[recordedTmpFile path] error:&error];

The reason is that, if an error occcurs, in setCategory:error: the existing value of error will be overwritten without being released and is thus a potential leak.

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • the lines with error are: 30 [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error]; 32 [audioSession setActive:YES error: &error]; 49 [fm removeItemAtPath:[recordedTmpFile path] error:&error]; 108 recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error]; 142 AVAudioPlayer * avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error]; – Javier Nov 29 '11 at 12:23
  • The solution... In .h --> NSError *__autoreleasing * error; In.m --> [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:error]; – Javier Nov 29 '11 at 12:42
  • @Javi: that's not the solution. Your instance variable will be nil and so not used. If that's what you want, just pass `nil` directly to the methods. – JeremyP Nov 29 '11 at 12:54
  • Here is correct answer to this question : http://stackoverflow.com/questions/6963538/error-passing-address-of-non-local-object-to-autoreleasing-parameter-for-writ – P.J Aug 30 '12 at 10:21