Memory Leak - NSString & NSURL

2019-07-30 11:49发布

@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...

2条回答
做自己的国王
2楼-- · 2019-07-30 12:30

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

Therefore filed as a bug:

Bug ID# 12699818.

查看更多
地球回转人心会变
3楼-- · 2019-07-30 12:38

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.

查看更多
登录 后发表回答