Memory Leak - NSString & NSURL

三世轮回 提交于 2020-01-05 22:42:09

问题


@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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!