问题
@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...
回答1:
Seems to be a memory leak in Core Foundation only in iOS 6.
Therefore filed as a bug:
Bug ID# 12699818.
回答2:
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.
来源:https://stackoverflow.com/questions/13309745/memory-leak-nsstring-nsurl