1
@property ( nonatomic, strong ) NSURL * urlPath;

self.urlPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bark" ofType:@"caf"]];

Running ARC, deployment target 4.3. Instruments gives a leak on the self.urlPath = line.

The self.urlPath is used later on after the view has appeared to setup the AVSoundPlayer. There is NO leak indicated now on the soundplayer, only on this NSURL line. The audio plays, but when the view is pop'd a memory leak occurs.

Any ideas as I've been at this > 12hrs now...

iOSProgrammingIsFun
  • 1,418
  • 1
  • 15
  • 32
  • Try using `URLForResource:withExtension:` method instead of `pathForResource:`, player also might be leaking. – ksh Nov 09 '12 at 14:50
  • Do you get the leak with all iOS SDK versions? – Simon Whitaker Nov 09 '12 at 18:44
  • Any reason why you're using `URLWithString:`? You'd typically use `fileURLWithPath:` to convert a file path to a `NSURL` instance. Not sure if that's in any way related to your leak, but worth having a look. – Simon Whitaker Nov 09 '12 at 18:47
  • I've changed the setupSound method to this: - ( void ) setupSound { NSURL * urlPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bark" ofType:@"caf"]]; self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:urlPath error:nil]; [self.player setVolume:0.5f]; } But I'm now getting a 100% leak on the NSURL line. The property for the audioplayer is this: @property ( nonatomic, strong ) AVAudioPlayer * player; I HAVE to use 4.3 deployment target and I'm using ARC – iOSProgrammingIsFun Nov 09 '12 at 18:52
  • Also, don't forget to call `[super viewDidAppear:animated]` and `[super viewWillDisappear:animated]`. – Simon Whitaker Nov 09 '12 at 18:54

2 Answers2

2

Seems to be a memory leak in Core Foundation only in iOS 6.

Therefore filed as a bug:

Bug ID# 12699818.

iOSProgrammingIsFun
  • 1,418
  • 1
  • 15
  • 32
0

Your player is leaking, and if your player leaks, every player will keep their URL and string object too.

self.player = [[[AVAudioPlayer alloc] initWithContentsOfURL:pingURL error:nil] autorelease];

If you declared player as a retaining property, then

self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:pingURL error:nil];

will leave the reference count at 2.

self.player = nil;

will make it 1.

jimpic
  • 5,360
  • 2
  • 28
  • 37
  • My player is a declared as: @property ( nonatomic, strong ) AVAudioPlayer * player; – iOSProgrammingIsFun Nov 09 '12 at 15:44
  • I have to support iOS 4.3, so I can't use 'weak' in the property declaration - is there something else I should be doing? I'm confused as to why the retain count is 2 after just a single alloc though... – iOSProgrammingIsFun Nov 09 '12 at 15:51
  • @iOSProgrammingIsFun use `assign` rather than `weak` — but be careful because that pointer won't automatically set itself to `nil` when the object is deallocated. But are you sure you don't want a `strong` reference that you simply deal with more correctly? – Tommy Nov 09 '12 at 22:12
  • strong is ok there and it is not the problem with arc @jimpic is not considering arc ... the count goes to 0 just fine. -- how about splitting you line? to better locate the prob – Daij-Djan Nov 09 '12 at 22:30
  • If I split the line, the NSString get's 33% of the leak and the NSURL gets 66%. 'assign', 'retain', 'strong', 'unsafe_unretained' or any combination make NO difference. – iOSProgrammingIsFun Nov 10 '12 at 12:39